PHP code example of matbcvo / laravel-token-auth

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

    

matbcvo / laravel-token-auth example snippets


use Illuminate\Support\Facades\Route;

Route::middleware('auth.token')->group(function () {
    Route::get('/protected-route', function () {
        return response()->json(['message' => 'You have access to this route!']);
    });
});

use Illuminate\Support\Facades\Route;
use Matbcvo\LaravelTokenAuth\Http\Middleware\AuthenticateApiToken;

Route::middleware(AuthenticateApiToken::class)->group(function() {
    Route::get('/protected-route', function () {
        return response()->json(['message' => 'You have access to this route!']);
    });
});

    'token_length' => 60,
    
bash
php artisan vendor:publish --provider="Matbcvo\LaravelTokenAuth\LaravelTokenAuthServiceProvider" --tag=migrations
bash
php artisan migrate
bash
php artisan api-token:list
bash
php artisan api-token:delete {id}
bash
php artisan vendor:publish --provider="Matbcvo\LaravelTokenAuth\LaravelTokenAuthServiceProvider" --tag=config