【问题标题】:Redirecting to the wrong URL laravel 5.1 authentication重定向到错误的 URL laravel 5.1 身份验证
【发布时间】:2015-11-11 14:14:03
【问题描述】:

我不知道我在这里做错了什么,每当我输入 URL:localhost/project/public/auth/login 它会将我重定向到 localhost/project/public/home,因此我收到错误:NotFoundHttpException

这是我的路线:

// Authentication routes...
Route::get('/auth/login', 'Auth\AuthController@getLogin');
Route::post('/auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');

// Registration routes...
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');


Route::controllers([
   'password' => 'Auth\PasswordController',
]);

我已经在 authController 中添加了这些:

protected $redirectPath = "/adminportfolio";
protected $loginPath = 'auth/login';
protected $redirectAfterLogout = '/index';

请有人在这里帮我..

【问题讨论】:

  • 好吧,你被重定向是因为你已经登录了。不过你应该被重定向到/adminportfolio。尝试从$redirectPath 中删除前导/
  • 感谢@BrokenBinary
  • 也发生在我身上:)

标签: laravel routes laravel-5.1


【解决方案1】:

从中间件中找到 RedirectIfAuthenticated 文件,如下所示:

<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Contracts\Auth\Guard;

class RedirectIfAuthenticated
{
    ...
    [----this file was truncated for simplicity----]
    ...

    public function handle($request, Closure $next)
    {
        if ($this->auth->check()) {
            return redirect('/home');
        }

        return $next($request);
    }
}

您会注意到redirect('/home'),您可能需要更改它以满足您的需要。

【讨论】:

    猜你喜欢
    • 2016-05-13
    • 2016-04-02
    • 2016-03-10
    • 1970-01-01
    • 1970-01-01
    • 2011-03-23
    • 2022-01-24
    • 2016-06-11
    • 1970-01-01
    相关资源
    最近更新 更多