PHP code example of cable8mm / laravel-api-key

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

    

cable8mm / laravel-api-key example snippets


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
sh
php artisan vendor:publish --tag=laravel-api-key-nova
sh
php artisan vendor:publish --tag=laravel-api-key-nova --force