Last active
May 17, 2019 20:11
-
-
Save farshidrezaei/f12ec21bd65f1180115c30afb2010f7f to your computer and use it in GitHub Desktop.
Simple Signed URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//define a route that in action validate signature | |
Route::get('signed', function (Request $request) { | |
if ( ! $request->hasValidSignature() ) { | |
abort( 404 ); | |
}else{ | |
//do something | |
} | |
})->name('signed'); | |
//alternative | |
//App/Http/Kernel.php | |
protected $routeMiddleware = [ | |
//... | |
'signed' => ValidateSignature::class, | |
]; | |
Route::get('signed', function (Request $request) { | |
//do something | |
})->name('signed')->middleware('signed'); | |
//generate signed link for 'signed' route | |
$signed_route = URL::temporarySignedRoute( 'signed', now()->addSeconds(10), ['user' => 1] ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment