【问题标题】:Cant redirect where I want it - laravel无法重定向到我想要的地方 - laravel
【发布时间】:2014-10-30 07:41:49
【问题描述】:

当我登录时,它应该将我重定向到 /spotlight,但它没有。如果您没有登录并且您尝试访问 /spotlight 它会将您重定向到登录。 知道为什么吗?

http://pastebin.com/ERVAj2eu

【问题讨论】:

  • 登录成功后会在哪里登陆?
  • 我想了很多:/ 请在下面查看我的答案。

标签: php laravel-4 frameworks laravel-routing


【解决方案1】:

您在为 Spotlight 提供路由之前运行 auth 过滤器,因此这必须检查用户是否已登录,如果未登录,则将他们重定向到登录页面。

在登录路径中你需要改变这个:

return Redirect::intended('/');

对此:

return Redirect::intended('/spotlight');

现在应该在登录后重定向到聚光灯路由。

【讨论】:

  • 登录后不重定向
  • 你登录成功了吗?在提供 Spotlight 路由之前运行的 auth 函数中有什么?
【解决方案2】:

试试

Redirect::route('spotlight');

并创建该路线

Route::get("/spotlight", array( "as" => "spotlight", "uses" => "Controller@function");

【讨论】:

    【解决方案3】:

    请重新编写您的“登录”路线,如下所示。根据您当前的逻辑,无论身份验证是否成功,您都会再次看到“登录”页面;您必须有一个else 子句,以便login 页面仅在身份验证失败时才重新加载

    Route::post('/login', function()
    {
        $credentials = Input::only('username', 'password');
        if (Auth::attempt($credentials)) {
            return Redirect::intended('/');
        }
        else
        {
            return Redirect::to('login');
        }
    });
    

    【讨论】:

      猜你喜欢
      • 2022-11-07
      • 1970-01-01
      • 2014-06-20
      • 1970-01-01
      • 2021-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-12
      相关资源
      最近更新 更多