简体   繁体   中英

why am i getting error message when using auth::attempt in laravel?

here is the code i am using :

if(Auth::attempt(['email'=>Input::get('email'),'password'=>Input::get('password')])) return Response::json('wellcome',404);

and here is the error message : Symfony \\ Component \\ HttpKernel \\ Exception \\ NotFoundHttpException

Controller method not found.

and here is the route :

Route::get('login','login@showLogin');
Route::post('login','login@doLogin');
Route::get('logout','login@logout');

the logout and show login works , the login works as well except for the part where i use attempt!!!! , when i comment out the line where Auth::attempt i written , no error message get displayed !!!!

I think it's because you are returning an status code of 404, which stands for Not Found .

Change this:

return Response::json('wellcome', 404);

to this:

return Response::json('wellcome', 200);

and see what happens. You can ommit the 200 parameter if you want, since it's the default value. Also keep in mind that in order to return a JSON object, you should use an array as first parameter:

return Response::json(['foo' => 'bar']);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM