Laravel Auth Handbook

·

2 min read

Laravel UI

composer require laravel/ui

//Then select the boardplate you like
php artisan ui bootstrap --auth
php artisan ui vue --auth
php artisan ui react --auth

npm install 
npm run dev
php artisan migrate

Laravel Breeze

Install Breeze with Blade

composer require laravel/breeze --dev
php artisan breeze:install
npm install 
npm run dev
php artisan migrate

Install Breeze with Inertia

php artisan breeze:install --inertia
npm install 
npm run dev
php artisan migrate

Laravel Jetstream

Install Jetstream with Livewire

composer require laravel/jetstream
php artisan jetstream:install livewire
npm install 
npm run dev
php artisan migrate

Install Jetstream with Inertia

php artisan jetstream:install inertia
npm install 
npm run dev
php artisan migrate

Laravel Fortify without Jetstream

//install fortify
composer require laravel/fortify

//publish configuration
php artisan vendor:publish --provider="Laravel\Fortify\FortifyServiceProvider"

Then add it to app/config/app.php

App\Providers\FortifyServiceProvider::class,

Enable or disable the Fortifay feature, in app/config/app.php

'features' => [
   Features::registration(),
   Features::resetPasswords(),
   // Features::emailVerification(),
   Features::updateProfileInformation(),
   Features::updatePasswords(),
   Features::twoFactorAuthentication([
      'confirmPassword' => true,
   ]),
],

Laravel Auth for REST API

Laravel Sanctum

Install Sanctum

composer require laravel/sanctum

Publish Configuration

php artisan vendor:publish --provider="Laravel\Sanctum\SanctumServiceProvider"

add to middleware for sanctum api, in app/Http/Kernel.php

'api' => [
    \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
    'throttle:api',
    \Illuminate\Routing\Middleware\SubstituteBindings::class,
],

Use it in the User model: app/Models/User.php

<?php

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
    use HasFactory, Notifiable, HasApiTokens;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name',
        'email',
        'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];
}

Final

php artisan migrate