Middleware Flashcards

1
Q

creating middleware

A

php artisan make:middleware EnsureTokenIsValid

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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);
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Delcare middleware name in app/Http/Kernel.php

A

‘Newmiddleware’ =>\App\Http\Middleware\NewMiddleware::class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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 () {
//
});
});

How well did you know this?
1
Not at all
2
3
4
5
Perfectly