PHP code example of nivekaa / laravel-api-key

1. Go to this page and download the library: Download nivekaa/laravel-api-key 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/ */

    

nivekaa / laravel-api-key example snippets


'providers' => [
    ...
    Nivekaa\LaravelApiKey\Providers\ApiKeyServiceProvider::class,
],

Route::get('api/user/1', function () {
    //
})->middleware('auth.apikey');


class UserController extends Controller
{
    /**
     * Instantiate a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth.apikey');
    }
}
bash
$ php artisan apikey:generate app1
  
// API key created
// Name: app1
// Key: 0ZdNlr7LrQocaqz74k6usQsOsqhqSIaUarSTf8mxnHuQVh9CvKAfpUy94VvBmFMq
bash
$ php artisan apikey:deactivate app1
  
// Deactivated key: app1
bash
$ php artisan apikey:activate app1
  
// Activated key: app1