PHP code example of zhitoo / jwt

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

    

zhitoo / jwt example snippets

 
    php artisan vendor:publish Zhitoo\Jwt\JWTServiceProvider
    php artisan jwt:secret
 

Route::middleware('auth:jwt')->get('/user', function (Request $request) {
    return $request->user();
});

Route::post('/login', function (Request $request) {
    $email = $request->input('email');
    $password = $request->input('password');
    if (\Illuminate\Support\Facades\Auth::attempt(['email' => $email, 'password' => $password])) {
        return response()->json(['ok' => true, 'token' => $request->user()->createToken()]);
    }
    abort(401);
});

Route::middleware('auth:jwt')->post('/logout', function () {
    if (method_exists(auth()->user(), 'revokeAccessToken')) {
        auth()->user()->revokeAccessToken();
    }
    return response()->json(['ok' => true]);

});