PHP code example of billyranario / laravel-passport-boilerplate

1. Go to this page and download the library: Download billyranario/laravel-passport-boilerplate library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

billyranario / laravel-passport-boilerplate example snippets


return [
    ..., // Other config
    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],

        // Add this following code below
        'api' => [
            'driver' => 'passport',
            'provider' => 'users',
        ],
    ],
];

    protected $middlewareAliases = [
        // other aliases....
        'admin.api' => \App\Http\Middleware\Admin\AdminApi::class, // <- Insert this line
    ];

use App\Models\User;
use App\Observers\UserObserver;


// INSIDE THE CLASS, ADD THIS
    /**
     * The model observers for your application.
     *
     * @var array
     */
    protected $observers = [
        User::class => [UserObserver::class],
    ];


    public function boot(): void
    {
        RateLimiter::for('api', function (Request $request) {
            return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
        });

        $this->routes(function () {
            Route::middleware('api')
                ->prefix('api')
                ->group(base_path('routes/api.php'));

            // INSERT THIS BLOCK
            Route::middleware('api')
                ->prefix('api/admin')
                ->group(base_path('routes/admin.php'));
            // END

            Route::middleware('web')
                ->group(base_path('routes/web.php'));
        });
    }
bash
php artisan passport:keys
php artisan passport:client --password
> psk-password-grant
> [0] users

php artisan passport:client --personal
> psk-personal-access