Laravel training.
- PHP Intelephese
- Prettier Code Formatter
- Blockman
- Laravel Blade Formatter
- Laravel Blade Snippets
- TailwindCSS Intellisense
- Vscode essentials
- vscode icons
- File Utils
- Laravel Goto View
composer global require laravel/installer
laravel new training --git --jet --stack=livewire
- Route -
routes/web.php
- Closure
- Method
- Resource
- Controller
app/Http/Controllers
- Invokable -
php artisan make:controller HelloWorldController -i
- Method -
php artisan make:controller HelloWorldController
- Resource -
php artisan make:controller UserController -r --model=User
- Invokable -
- View
- located
resources/views
- with
.blade.php
extension
- located
Run the following command during development:
npm install
Run the Vite:
npm run dev
Compile assets for production:
npm run build
You may want to run the build command in production OR commit the
public/builds
in your repository.
php artisan tinker
> \App\Models\User::factory(1000)->create();
Create seeder
php artisan make:seeder DummySeeder
Seed data:
php artisan db:seed
Seed data specific to seeder class:
php artisan db:seed --class=DummySeeder
php artisan tinker
Then update the email and run the following:
\App\Models\User::where('email','[email protected]')->update(['password' => Hash::make('password')]);
Create policy:
php artisan make:policy UserPolicy --model=User
Using policy in Blade file:
@can('view', $user)
...
@endcan
Using policy in controller:
public function show(User $user)
{
$this->authorize('view', $user);
}
Using policy in resource controller:
public function __construct()
{
$this->authorizeResource(\App\Models\User::class);
}
Using policy from current user logged in.
if(auth()->user()->can('viewAny', \App\Models\User::class)) {
...
}
Using policy from user's object / current user logged in.
if($user->can('viewAny', \App\Models\User::class)) {
...
}
Using custom policy name:
public function download(User $user): bool
{
return true;
}
$user->can('download', \App\Models\User::class);