Class 'App\Http\Controllers\Session' not found in Laravel 5.2
Ad
I am using sessions in Laravel 5.2 . There is my Controller code:
if (Session::has('panier'))
{
$panier = Session::get('panier');
}
I try just to get a value from the session, and I got this error:
FatalErrorException in ProduitsController.php line 106: Class 'App\Http\Controllers\Session' not found
How can I resolve it?
Ad
Answer
Ad
From the error message:
Class 'App\Http\Controllers\Session' not found
I see that Laravel is searching the Session
class in the current namespace: App\Http\Controllers
The problem is you don't have aliased the class from the global namespace: Session
is a Facade, and all the facades are in the global namespace
To use the class from the global namespace, put:
use Session;
on top of your controller, after your namespace declaration
Alternatively, you can call the class from the global namespace with:
\Session::get('panier');
Ad
source: stackoverflow.com
Related Questions
Ad
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad