doqp87012 2017-03-10 21:48
浏览 91
已采纳

Laravel Auth隐藏重定向

Install new Laravel 5.4 project.

Run php artisan make:auth.

Go to http://localhost:8000/home (without being logged in).

I get redirected to http://localhost:8000/login

This redirect seems like magic. This is the route for home:

|| GET|HEAD |home||App\Http\Controllers\HomeController@index|web,auth|

We never get to the index() method because the auth middleware takes over. I open the auth middleware file Illuminate\Auth\Middleware\Authenticate.php and there's no mention of the /login redirect.

Where is the redirect from /home to /login defined?

  • 写回答

1条回答 默认 最新

  • dongzhang1987 2017-03-10 22:07
    关注

    Check app/Exceptions/Handler.php file and you'll see Exception handler for unauthenticated users:

    protected function unauthenticated($request, AuthenticationException $exception)
    {
        if ($request->expectsJson()) {
            return response()->json(['error' => 'Unauthenticated.'], 401);
        }
    
        return redirect()->guest(route('login'));
    }
    

    P.S. redirect to home you can see in app/Http/Middleware/RedirectIfAuthenticated.php file.

    UPD1: redirect to home after login/register you can set in app/Http/Controllers/Auth/LoginController.php and app/Http/Controllers/Auth/RegisterController.php. It looks like

    protected $redirectTo = '/home';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?