Middleware Flashcards
1
Q
creating middleware
A
php artisan make:middleware EnsureTokenIsValid
2
Q
In New middleware class from app/Http/Middleware
A
public function handle($request, Closure $next) { if ($request->input('token') !== 'my-secret-token') { return redirect('home'); }
return $next($request); }
3
Q
Delcare middleware name in app/Http/Kernel.php
A
‘Newmiddleware’ =>\App\Http\Middleware\NewMiddleware::class
4
Q
middleware in route
A
Route::get('/profile', function () { // })->middleware('auth');
----------------------------------------------------------------------------- with class file
use App\Http\Middleware\EnsureTokenIsValid;
Route::get('/profile', function () { // })->middleware(EnsureTokenIsValid::class);
5
Q
exclude middleware in group
A
use App\Http\Middleware\EnsureTokenIsValid;
Route::middleware([EnsureTokenIsValid::class])->group(function () { Route::get('/', function () { // });
Route::get('/profile', function () { // })->withoutMiddleware([EnsureTokenIsValid::class]); });
Exclude middleware group
Route::withoutMiddleware([EnsureTokenIsValid::class])->group(function () {
Route::get(‘/profile’, function () {
//
});
});