PHP code example of rcerljenko / laravel-paseto

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

    

rcerljenko / laravel-paseto example snippets


// config/auth.php

'guards' => [
 'web' => [
  'driver' => 'session',
  'provider' => 'users',
 ],

 'api' => [
  'driver' => 'paseto',
  'provider' => 'users',
 ],
],

// routes/api.php

use Illuminate\Support\Facades\Route;

Route::middleware('auth:api')->group(function () {
 // PASETO protected routes
});

namespace App\Models;

use Illuminate\Notifications\Notifiable;
use RCerljenko\LaravelPaseto\Traits\HasPaseto;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
 use Notifiable, HasPaseto;
}

$user = User::findOrFail(1);
$user->token();

$user->token([
 'id' => $user->email,
 'valid_from' => now()->addHour(),
 'valid_until' => now()->addDay(),
 'claims' => [
  'extra1' => 'foo',
  'extra2' => 'bar'
 ]
]);
sh
php artisan vendor:publish --provider="RCerljenko\LaravelPaseto\LaravelPasetoServiceProvider" --tag="config"