0
我使用中間件路由組和具有三個中間件admin
,teacher
和teacheradmin
好管理工作正常,但假設我有10路和下組teacheradmin
(工作情況下,所有的人都定義現在)
但我想只有那些10路的5至中間件teacher
進行,所有10至中間件訪問teacheradmin
與laravel嵌套航線組工作
我這是怎麼嵌套的路線組
Route::group(['middleware' => 'teacheradmin'], function() {
//defined 5 routes only accessible by teacheradmin
Route::group(['middleware' => 'teacher'], function() {
//defined the other routes accessible by both teacher and teacheradmin
});
});
但是上面築巢不工作,teacheradmin
是不能訪問下teacher
PLZ我需要一個方向定義的路線我怎樣才能使它發揮作用
更新:
按答案我已經定義中間件陣列,用於共同路由
Route::group(['middleware' => ['teacher', 'teacheradmin']], function() {
//defined common routes
});
和TEH 2箇中間件手柄方法是:
老師
public function handle($request, Closure $next)
{
if(Auth::check())
{
if(Auth::user()->user_type != 'TEACHER')
{
return redirect()->route('dashboard');
}
return $next($request);
}
else
{
return redirect('/')
->withErrors('That username/password does not match, please try again !!!.');
}
}
teacheradmin
public function handle($request, Closure $next)
{
if(Auth::check())
{
if(Auth::user()->user_type != 'TEACHER_ADMIN')
{
return redirect()->route('dashboard');
}
return $next($request);
}
else
{
return redirect('/')
->withErrors('That username/password does not match, please try again !!!.');
}
}
和儀表板的路線進入這個方法
public function Dashboard(Request $request)
{
$user = Auth::user();
if($user->user_type === 'ADMIN') {
return redirect()->route('dashboardadmin');
} else if($user->user_type === 'TEACHER_ADMIN') {
return redirect()->route('dashboardteacher');
} else if($user->user_type === 'TEACHER') {
return redirect()->route('world_selection');
} else {
return redirect()->route('dashboardchild');
}
}
我現在面臨的問題是,當我在儀表盤我嘗試訪問作爲teacheradmin
的共同路線,那麼它也去teacher
的句柄,因此又回到同一頁
任何特定的代碼要寫入中間件句柄,因爲當我試圖訪問第二組(普通組)下的任何路由作爲teacheradmin,即使它然後去教師中間件句柄,因此不工作 – Uttara
您是否可以更新您的問題中間件代碼?我不確定你想要做什麼。 –
查看我的更新以獲取替代方案。 –