Skip to content

nasrulhazim/training-laravel-mu-dot-my

Repository files navigation

Training: Web Development with Laravel Framework (Basic) at mu dot my

Laravel training.

VS Codes Extensions

  • PHP Intelephese
  • Prettier Code Formatter
  • Blockman
  • Laravel Blade Formatter
  • Laravel Blade Snippets
  • TailwindCSS Intellisense
  • Vscode essentials
  • vscode icons
  • File Utils
  • Laravel Goto View

Install Laravel installer

composer global require laravel/installer

Create Laravel Application

laravel new training --git --jet --stack=livewire

Create a page

  • 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
  • View
    • located resources/views
    • with .blade.php extension

Vite

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.

Database: Factory

php artisan tinker
> \App\Models\User::factory(1000)->create();

Database: Seeder

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

Update Password throught Tinker

php artisan tinker

Then update the email and run the following:

\App\Models\User::where('email','[email protected]')->update(['password' => Hash::make('password')]);

Authorization: Policy

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);

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages