I am using session in Laravel 5.2 and here is my Controller code :
if ($request->session()->has('username')) {
return view('dashboard');
}
I need to use session, and getting this error :
FatalErrorException in HomeController.php line 21: Call to undefined method Illuminate\Support\Facades\Request::session()
How to resolve it ?
Not sure where you have $request
coming from, but more than likely you have the wrong type being injected.
If you just want the $request
instance you would want to use Illuminate\Http\Request
Kinda looks like you are having the Facade injected instead.
Request
(in root namespace) is the Facade that is aliased.
Illuminate\Http\Request
is the actual request class you want the instance of.
Try put this at your file begin:
use Illuminate\Http\Request;
I had the same problem and solved this way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With