1. Go to this page and download the library: Download laragear/token-action 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/ */
laragear / token-action example snippets
use Laragear\TokenAction\Facades\Token;
$token = Token::until('tomorrow');
return "Confirm the invite using this code: $token";
use Laragear\TokenAction\Facades\Token;
// Create a token for 10 minutes
$token = Token::until(10);
// Create a token for tomorrow
$token = Token::until('tomorrow');
// Create a token for a specific moment of time
$token = Token::until(now()->addHour());
use Laragear\TokenAction\Facades\Token;
$token = Token::tries(2)->until('tomorrow');
use Laragear\TokenAction\Facades\Token;
$token = Token::with(['cool' => true])->until('tomorrow');
use Laragear\TokenAction\Facades\Token;
use App\Models\Tour;
use App\Models\Party;
// Use a single model
$token = Token::with(Party::find(420))->until('tomorrow');
// Use a collection
$token = Token::with(Tour::limit(10)->get())->until('tomorrow');
use Laragear\TokenAction\Facades\Token;
$token = Token::find('e9f83d...');
if ($token) {
$party = $token->payload->party->name;
return "You confirmed the invitation to $party";
}
return 'You need to be invited the first place.';
use Laragear\TokenAction\Facades\Token;
$token = Token::consume('e9f83d...');
if ($token) {
return 'You are confirmed your invitation to the party!'.
}
use Laragear\TokenAction\Facades\Token;
Token::consumeOrFail('e9f83d...');
return 'You are confirmed your invitation to the party #420';
use Laragear\TokenAction\Facades\Token;
$token = Token::find('e9f83d...');
if ($token?->consume()) {
return 'Assistance confirmed!';
}
return 'You are not invited';
use Laragear\TokenAction\Facades\Token;
$token = Token::findOrFail('e9f83d...');
$token->consume();
return 'Assistance confirmed!';
use App\Models\Party;
use Illuminate\Support\Facades\Route;
use Laragear\TokenAction\Token;
Route::get('party/{party}/invitation/{token}', function (Party $party, Token $token) {
return view('party.confirm')->with([
'party' => $party,
'token' => $token,
]);
})
use Laragear\TokenAction\Facades\Token;
$token = Token::find('e9f83d...');
if ($token) {
$token->delete();
}
use Laragear\TokenAction\Facades\Token;
Token::destroy('e9f83d...');
use Laragear\TokenAction\Facades\Token;
$partyToken = Token::store('redis')->find('e9f83d...');
$dateToken = Token::store('memcached')->find('e9f83d...');
use Illuminate\Support\Facades\Route;
use App\Models\Party;
// Show the form to confirm the invitation.
Route::get('{party}/confirm', function (Party $party) {
return view('party.confirm')->with('party', $party);
})->middleware('token.validate');
use Illuminate\Support\Facades\Route;
use Illuminate\Http\Request;
use App\Models\Party;
// Show the form to confirm the invitation.
Route::get('{party}/confirm', function (Party $party) {
// ...
})->middleware('token.validate');
// Handle the form submission.
Route::post('{party}/confirm', function (Request $request, Party $party) {
$party->confirmInviteForUser($request->user());
return back();
})->middleware('token.consume');
use Illuminate\Support\Facades\Route;
use Illuminate\Http\Request;
use App\Models\Party;
Route::get('{party}/confirm', function (Party $party) {
// ...
})->middleware('token.validate:token-action');
Route::post('{party}/confirm', function (Request $request, Party $party) {
// ...
})->middleware('token.consume:token-action');
use Illuminate\Support\Facades\Route;
use Illuminate\Http\Request;
use App\Models\Party;
Route::post('{party}/confirm', function (Request $request, Party $party) {
// ...
})->middleware('token.consume:2');
use Laragear\TokenAction\Facades\Token;
use Illuminate\Support\Str;
$token = Token::store('redis')->as(Str::random(32))->until(60);
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Str;
use Laragear\TokenAction\Token;
class AppServiceProvider extends ServiceProvider
{
public function boot()
{
Token::$generator = fn() => Str::random(48);
}
}
use Illuminate\Support\Facades\Route;
use Laragear\TokenAction\Http\Middleware\TokenValidateMiddleware;
Route::get('invite', function () {
// ...
})->middleware(TokenValidateMiddleware::class)