我使用的是laravel 5.1,用户登录后,用户仍然可以访问login
和register
的url。
我目前的路线实现如下:
<?php
$s = 'public.';
Route::get('/', ['as' => $s . 'home', 'uses' => 'PagesController@getHome']);
$a = 'auth.';
Route::get('/login', [ 'as' => $a . 'login', 'uses' => 'Auth\AuthController@getLogin']);
Route::post('/login', ['as' => $a . 'login-post', 'uses' => 'Auth\AuthController@postLogin']);
Route::get('/register', ['as' => $a . 'register', 'uses' => 'Auth\AuthController@getRegister']);
Route::post('/register', ['as' => $a . 'register-post', 'uses' => 'Auth\AuthController@postRegister']);
Route::get('/password', ['as' => $a . 'password', 'uses' => 'Auth\PasswordResetController@getPasswordReset']);
Route::post('/password', ['as' => $a . 'password-post', 'uses' => 'Auth\PasswordResetController@postPasswordReset']);
Route::get('/password/{token}', ['as' => $a . 'reset', 'uses' => 'Auth\PasswordResetController@getPasswordResetForm']);
Route::post('/password/{token}',['as' => $a . 'reset-post', 'uses' => 'Auth\PasswordResetController@postPasswordResetForm']);
$s = 'social.';
Route::get('/social/redirect/{provider}', ['as' => $s . 'redirect', 'uses' => 'Auth\AuthController@getSocialRedirect']);
Route::get('/social/handle/{provider}', ['as' => $s . 'handle', 'uses' => 'Auth\AuthController@getSocialHandle']);
Route::group(['prefix' => 'admin', 'middleware' => 'auth:administrator'], function()
{
$a = 'admin.';
Route::get('/', ['as' => $a . 'home', 'uses' => 'AdminController@getHome']);
});
Route::group(['prefix' => 'user', 'middleware' => 'auth:user'], function()
{
$a = 'user.';
Route::get('/', ['as' => $a . 'home', 'uses' => 'UserController@getHome']);
});
Route::group(['middleware' => 'auth:all'], function()
{
$a = 'authenticated.';
Route::get('/logout', ['as' => $a . 'logout', 'uses' => 'Auth\AuthController@getLogout']);
});
我尝试了以下方法,但没有成功:
Route::get('/login', ['before'=> 'auth', 'as' => $a . 'login', 'uses' => 'Auth\AuthController@getLogin']);
谢谢!!
最佳答案
您需要为登录实现一个帮助程序(中间件)来进行重定向。检查 app/Http/Middleware/RedirectIfAuthenticated.php 这是一个很好的例子。无需为此创建路由。
关于php - Laravel 验证登录路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32720735/