PHP code example of ipimpat / laravel-api-key

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

    

ipimpat / laravel-api-key example snippets


'providers' => [
    ...
    Ejarnutowski\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