php – 在Auth :: attempt()Laravel 5.1中禁用重定向

前端之家收集整理的这篇文章主要介绍了php – 在Auth :: attempt()Laravel 5.1中禁用重定向前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用Laravel创建REST API.我是在登录API,所以我使用从Laravel构建它的AuthController.

但是,当我在第一次成功获取用户信息时使用Auth :: attempt()验证用户登录时,我调用方法Auth :: user().
但是,当我第二次再次运行时,我得到以下错误

NotFoundHttpException in RouteCollection.PHP line 161:

我知道如果用户已经过身份验证,它会自动发送重定向.并保存会话.

这是我在AuthController.PHP中的登录代码

public function demo() {

        if (Auth::attempt(Input::only('email','password'))) {
            return Auth::user();
        } else {
            return "false";
        }
    }

我写这样的路线:

Route::post('demo','Auth\AuthController@demo');

在这种情况下如何禁用重定向
因为我想从我的移动应用程序调用我的API.

谢谢

解决方法

Answer

Okay i get the solution,but it’s not elegant way. I edit the class
RedirectIfAuthenticated and remove return redirect(/home) in
handle method.

猜你在找的Laravel相关文章