我对拉拉维尔路线有问题。我希望只有管理员或登录用户才能访问该身份验证注册路由。为了实现这一点,我从路由中删除了Route::auth();
.php并在身份验证中间件中创建自己的路由条目。
努力
Route::group(['middleware' => 'web'], function () {
// Authentication Routes...
$this->get('login', 'AuthAuthController@showLoginForm');
$this->post('login', 'AuthAuthController@login');
$this->get('logout', 'AuthAuthController@logout');
// Password Reset Routes...
$this->get('password/reset/{token?}', 'AuthPasswordController@showResetForm');
$this->post('password/email', 'AuthPasswordController@sendResetLinkEmail');
$this->post('password/reset', 'AuthPasswordController@reset');
Route::get('/home', 'HomeController@index');
Route::post('/ajax/getStates', 'ConfigurationController@getStates');
Route::post('/ajax/getCities', 'ConfigurationController@getCities');
});
Route::group(['middleware' => ['web','auth']], function () {
// Registration Routes...
$this->get('register', 'AuthAuthController@showRegistrationForm');
$this->post('register', 'AuthAuthController@register');
});
上面的代码工作正常。 当我尝试访问注册 URL 时,它只是将我重定向到登录页面。现在实际问题在登录后开始。
登录后,我尝试访问注册页面,但它没有显示,而是像http://localhost/
一样将我重定向到主页。
请向我建议解决方案。
检查 AuthController 的构造函数。它将来宾中间件分配给除logout
以外的所有方法。
我得到了一个简单的解决方案。我不是专家,但我以这种方式进行,它正在按照您想要的方式工作。
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('/edit', function () {
if (Auth::user()) {
return view('auth.user_edit'); //Page which you want to show for loged user.
} else {
return "MM"; //You can redirect from here, if user is not logged in
}
});
});