PHP code example of jhumanj / laravel-signed-auth-middleware

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

    

jhumanj / laravel-signed-auth-middleware example snippets


return [
    'signature_param_name' => 'auth-signature', 
    'default_expire' => 60,
    'remember_login' => true,
    'user_guard' => 'web'
];

use Illuminate\Foundation\Http\Kernel as HttpKernel;
use JhumanJ\LaravelSignedAuthMiddleware\Traits\HasSignedAuth;

class Kernel extends HttpKernel
{
    use HasSignedAuth;

    // ... 
    
    public function __construct(Application $app, Router $router)
    {
        parent::__construct($app, $router);

        $this->setupSignedAuthMiddleware();
    }
}
 
   // App/Http/Kernel.php
   
   protected $middlewareGroups = [
        'web' => [
            // ...
            \JhumanJ\LaravelSignedAuthMiddleware\SignedAuthMiddleware::class,
        ],
    ];

// Kernel.php
protected $routeMiddleware = [
    'auth.signed' => \JhumanJ\LaravelSignedAuthMiddleware\SignedAuthMiddleware::class,
];
 
// routes/web.php
Route::get('/', function () {
    return view('welcome');
})->middleware('auth.signed','auth');
 
use JhumanJ\LaravelSignedAuthMiddleware\Facades\SignedAuth;

$signedUrl = SignedAuth::forUser($user)
                ->route('welcome')
                ->generate();
 
use JhumanJ\LaravelSignedAuthMiddleware\Facades\SignedAuth;

$signedUrl = SignedAuth::forUser($user)
                ->expired(60*24) // expires in 24 hours
                ->route('welcome')
                ->generate();
 
use JhumanJ\LaravelSignedAuthMiddleware\Facades\SignedAuth;

$signedUrl = SignedAuth::forUser($user)
                ->neverExpires()
                ->route('welcome')
                ->generate();
 
use JhumanJ\LaravelSignedAuthMiddleware\Facades\SignedAuth;

$signedUrl = SignedAuth::forUser($user)
                ->route('welcome',[
                    'utm_source' => 'source',
                    'utm_medium' => 'medium',
                    'utm_campaign' => 'utm_campaign'
                ])
                ->generate();
bash
php artisan vendor:publish --tag="laravel-signed-auth-middleware-config"