php - Laravel 验证登录路径

标签 php laravel laravel-5

我使用的是laravel 5.1,用户登录后,用户仍然可以访问loginregister的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/

相关文章:

php - 如何在 Packagist 中重命名 PHP 包

PHP 在类中打印错误

php - 无法将 S3 与 Laravel 5.4 一起使用

php - HTML 标签中的三元运算符 - Laravel 5.6 Blade 模板

php - CodeIgniter:如何将 $this->db->insert_id() 值传递给 Controller 以便插入到另一个表中?

php - Laravel 5.5 - 事件上的 SerializesModels 导致 ModelIdentifier 错误?

php - 将用户与他们创建的标签联系起来,而不会在 mysql 数据库中有重复的内容

mysql - 从第三个表中检索与两个数据透视表匹配的行

php - Laravel Eloquent 另一个表中列的总和

javascript - 当我在 HTML 中调用它时,为什么我的 Javascript 函数不运行/工作?