0
我使用Laravel 5.4的項目和方案是,如果user
沒有創造那麼在登錄重定向user
到clubs/create
頁任何clubs
。Laravel路由重定向次數太多
下面是我的路線頁面編碼
目錄結構routes/backend/access.php
Route::group([
'prefix' => 'access',
'as' => 'access.',
'namespace' => 'Access',
], function() {
Route::group([
'middleware' => ['access.routeNeedsRole:3', 'first.run']
], function() {
/*
* Clubs Management
*/
Route::group(['namespace' => 'Clubs'], function() {
Route::get('create', '[email protected]')->name('clubs.showCreateOrganiser');
/*
* Specific Club
*/
Route::group(['prefix' => 'clubs/{club}'], function() {
// Access
Route::get('login-as', '[email protected]')->name('clubs.login-as');
});
//For when admin is logged in as user from backend
Route::get('logout-as', '[email protected]')->name('clubs.logout-as');
/*Clubs CRUD*/
Route::resource('clubs', 'ClubsController');
//For DataTables
Route::post('clubs/get', 'ClubsTableController')->name('clubs.get');
});
});
});
下面是我FirstRunMiddleware.php
代碼
Class FirstRunMiddleware
{
public function handle($request, Closure $next)
{
if (Clubs::scope()->count() === 0) {
return redirect()->route('admin.access.clubs.showCreateOrganiser');
}
$response = $next($request);
return $response;
}
}
它重定向過很多次,我也得到該錯誤消息redirected you too many times
。
這是什麼我在這裏做錯了?
Git it。需要添加if條件。謝謝。 –