Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.2 - Call to undefined method Illuminate\Support\Facades\Request::session()

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 ?

like image 534
Honest Knight Avatar asked Dec 29 '15 20:12

Honest Knight


2 Answers

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.

like image 134
lagbox Avatar answered Oct 15 '22 19:10

lagbox


Try put this at your file begin:

use Illuminate\Http\Request;

I had the same problem and solved this way.

like image 43
Marcelo Agimóvel Avatar answered Oct 15 '22 19:10

Marcelo Agimóvel