=> " Middleware can also receive additional parameters. "
=> " For example, if your application needs to verify that the
authenticated user has a given "role" before performing a given action, "
=> "Additional middleware parameters will be passed to the middleware after the $next argument:"
=> Middleware parameters may be specified when defining the route by
separating the middleware name and parameters with a :.
Multiple parameters should be delimited by
commas:
=> in route
Route::put('/post/{id}', function ($id) {
//
})->middleware('role:editor');
=> in Middleware
<?php
namespace App\Http\Middleware;
use Closure;
class EnsureUserHasRole
{
public function handle($request, Closure $next, $role)
{
if (! $request->user()->hasRole($role)) {
// Redirect...
}
return $next($request);
}
}
No comments:
Post a Comment