ミドルウェアにパラメータを渡すロールミドルウェアがあります。役割ミドルウェア動的パラメータLaravel 5.4
public function __construct(UserInterface $user, RoleInterface $role, MaritalStatusInterface $maritalStatus, CityInterface $city){
$this->middleware('auth');
//$this->middleware('role:System Admin'); I changed it to 6 for the id.
$this->middleware('role:6');
}
私RoleMiddlewareは、あなたはそれが非常に6
に結び付けられているIを見ることができるように、この
public function handle($request, Closure $next, ...$params)
{
$roles = $request->user()->roles()->get();
$roles = $roles->map(function($item){
return $item->id;
});
foreach ($params as $value) {
if(! in_array($value, $roles->toArray())){
return redirect()->action('[email protected]');
}
}
return $next($request);
}
です。 7
を追加したい場合はどうすればいいですか...動的にしたいのですが。私のテーブルはUsers
とRoles
です。どのテーブルが必要か、それを実行する方法。
を爆発すべき行う必要があります'$ this-> middleware( 'role:6');'このスクリプトはどこにありますか?コントローラーで? – Demonyowh
コントローラを更新しました。スクリプトはAdminControllerにあります。ありがとう – Rbex