How to Install API Routes in Laravel 11
In this tutorial, we will see how to install API routes in Laravel 11, the release of Laravel 11 comes with huge changes one of them is removing the API routes so how we can use them again?
Install the API Routes
So to bring back the API Routes again run the command:
php artisan install:api
Update the User Model
Once done add the Trait HasApiTokens to your User Model.
<?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;
}