1

I am using Sentinel package for advanced authentication in laravel. I can register properly, but when I am going to login then here is an error like - 'The Response content must be a string or object implementing __toString(), "boolean" given.' Please anyone help me.

Here is my routes bellow:

 Route::get('/login', 'LoginController@login');
 Route::post('/login', 'LoginController@postLogin');

Here is my controller bellow:

 public function login(){
    return view('authentication.login');
}

public function postLogin(Request $request){
    Sentinel::authenticate($request->all());
    return Sentinel::check();
}
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
Rashed Hasan
  • 3,721
  • 11
  • 40
  • 82

3 Answers3

1

Here is an interesting thing about laravel response. What ever you return from laravel controller as response it tries to convert that array/object into string. But to convert an object into string is possible through the PHP magic method called __toString().

As you are not returning an object that has the implementation of __toString() method you are getting this error.

If you really want to see the output of Sentinel::check() then you can use dd(Sentinel::check()) instead of returning it. Besides you can even return it like ['sentinelCheck' => Sentinel::check()] if you really want.

Imran
  • 4,582
  • 2
  • 18
  • 37
0

Sentinel::check() return a boolean, when the user is authenticated it returns the user otherwise false.

https://cartalyst.com/manual/sentinel/2.0#sentinel-check

you can use a if statement to return a response:

if(Sentinel::check()){
    // authenticated
} else {
    // not authenticated
    return redirect()->back();
}
MrChrissss
  • 271
  • 1
  • 2
  • 11
0

The same thing happened to me. Fixed issue when sending array as return.

controller

return ['status' => true, 'msg' => 'mesaj', 'data' => 'datalar'];
T.Arslan
  • 123
  • 8