Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon Can the install:api command be used with Laravel Passport instead of Sanctum
    laravel 11


Can the install:api command be used with Laravel Passport instead of Sanctum


Yes, the `install:api` command in Laravel 11 can be used with Laravel Passport instead of Sanctum. To do this, you would run the command with the `--passport` option, like so:

bash
php artisan install:api --passport

This command will:

1. Create the `routes/api.php` File: It generates the API routes file where you can define your API endpoints.

2. Install Laravel Passport: It sets up Laravel Passport, which is an OAuth2 server implementation for API authentication. This includes publishing necessary configuration files and running database migrations to create the required tables for storing OAuth2 clients and access tokens.

3. Generate Encryption Keys: The command will also create the encryption keys needed for generating secure access tokens.

4. Prompt for UUIDs: You may be prompted to choose whether to use UUIDs as the primary key for the Passport Client model instead of auto-incrementing integers.

After running the command, you will need to add the `Laravel\Passport\HasApiTokens` trait to your `User` model and configure the `api` guard in your `config/auth.php` file to use Passport for authentication[1][2][4].

Citations:
[1] https://artisan.page/11.x/installapi
[2] https://laravel.com/docs/11.x/passport
[3] https://blog.logrocket.com/laravel-passport-a-tutorial-and-example-build/
[4] https://adevait.com/laravel/api-authentication-with-laravel-passport
[5] https://www.turing.com/kb/implementing-user-authentication-using-laravel-passport