Hi guys, I put the code below in my controller(I'm using Laravel 5):
if(Session::has('user')){ return view('home.index'); }else{ App::abort(404); }
and I got the following error:
Whoops, looks like something went wrong.
1/1 FatalErrorException in HomeController.php line 20: Class 'App\Http\Controllers\Session' not found
When I use Session::has('user') in the view tho everything looks fine.
Can anyone show me the right way of using Session object in controller?
Many thanks
Ok, I got it fixed. I forgot the namespace...
Hey nicholascc, what do you mean you forgot the namespace? I'm getting the same error when trying to use Session::flash from a controller (also L5). Any help?
thetimmyc said:
Hey nicholascc, what do you mean you forgot the namespace? I'm getting the same error when trying to use Session::flash from a controller (also L5). Any help?
add use Session; line below the opening php tag in your controller to use Session class in laravel 5.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community