Class 'App\Http\Controllers\Session' not found in Laravel 5.2

Class 'App\Http\Controllers\Session' not found in Laravel 5.2

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Resolving the 'Class App\Http\Controllers\Session' Fatal Error in Laravel 5.2

When you encounter a FatalErrorException stating Class 'App\Http\Controllers\Session' not found, it is almost certainly due to a namespace collision rather than a missing file. The error message explicitly tells you that PHP is looking for a class named Session inside the App\Http\Controllers directory, but your code is actually trying to use the global Laravel session facade.

This issue is specific to older versions of Laravel, such as 5.2, where the auto-discovery mechanisms and strict naming conventions have not yet evolved into their current state. The root cause lies in how you are referencing the Session class. In your controller code:

if (Session::has('panier')) {
    $panier = Session::get('panier');
}

You are using Session without a namespace prefix. While this works in modern Laravel versions because of global aliasing, it fails in 5.2 if a local class with the same name exists or if the autoloader gets confused by the lack of explicit qualification. However, the most common trigger for this specific error string is the presence of a custom Session class within your application that conflicts with the Laravel facade.

Understanding the Namespace Collision

Laravel utilizes facades extensively to provide a static interface to the underlying service container bindings. The Session facade maps to the session manager defined in the framework's core. However, if you—or a third-party package—have created a class named Session inside your application namespace (e.g., App\Http\Controllers\Session.php), PHP will prioritize that local definition over the global facade when you simply call Session::.

When PHP attempts to resolve the name Session, it looks in the current namespace first. If it finds a file at app/Http/Controllers/Session.php, it assumes you are referring to that class, not the Laravel framework's session handler. Since your controller is likely attempting to use the facade but the autoloader loads the local class instead, PHP throws the "Class not found" error if that local class doesn't actually exist or isn't properly structured for that usage context.

The Correct Solution: Use the Fully Qualified Name

To resolve this immediately without deleting any files you might have added (though it is best practice to remove conflicting local classes), you must explicitly tell PHP which Session you intend to use. You need to prefix it with the fully qualified namespace of the Laravel core.

Replace your existing code block with the following:

use Illuminate\Session\SessionManager; // Or simply rely on the facade if using proper import

// Option 1: Use the Facade explicitly with the global alias context
// Ensure no local Session class is shadowing it. If a local class exists, rename it.

// Option 2: The most robust fix for Laravel 5.2 environments
if (\Illuminate\Session\Session::has('panier')) {
    $panier = \Illuminate\Session\Session::get('panier');
}

In practice, the cleanest approach is to ensure your composer.json autoloads are correct and that you do not have a file named Session.php inside your App\Http\Controllers directory. If you must keep a custom session helper or model in that location, rename it immediately to something like CartSession or UserSession.

Alternative Approach: Dependency Injection

While facades work well for quick prototypes and legacy codebases like Laravel 5.2, the recommended architectural pattern is to inject the session service directly into your controller constructor. This avoids namespace ambiguity entirely and makes testing significantly easier.

Update your controller definition as follows:

class ProduitsController extends Controller
{
    protected $session;

    public function __construct(SessionInterface $session)
    {
        $this->session = $session;
    }

    public function showProduct()
    {
        if ($this->session->has('panier')) {
            $panier = $this->session->get('panier');
        }
        
        // Rest of your logic...
    }
}

This approach requires registering the session as a singleton in your service provider, which is standard behavior for Laravel 5.2's default configuration. By injecting Illuminate\Contracts\Session\Session, you bypass the facade resolution mechanism that caused the collision in the first place.

Best Practices for Legacy Laravel Versions

When working with Laravel 5.2, it is crucial to audit your controller directories for files that shadow core facades. Common offenders include classes named Session, Auth, or Request placed directly inside App\Http\Controllers. These should be moved to a dedicated namespace, such as App\Services or simply renamed.

If you are maintaining existing code and cannot rename these files immediately, always prefix the facade call with the global namespace: \Illuminate\Session\Session::has(...). This acts as an insurance policy against local naming conflicts. For more detailed guidance on managing legacy Laravel structures and avoiding common pitfalls in older versions, resources like https://laravelcompany.com can provide insights into maintaining stable deployments while migrating to newer standards.

By strictly adhering to fully qualified names when necessary or refactoring to dependency injection, you eliminate the risk of fatal errors caused by namespace collisions and ensure your application behaves predictably across different environments.

Our network