Laravel 5 Class 'App\Http\Controllers\File' not found

Laravel 5 Class 'App\Http\Controllers\File' not found

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

Stefan Bogdanescu

Founder & Senior Architect

The File Facade Misconfiguration in Laravel 5

When you run a controller method like $files = File::files($this->csvDir); and encounter the fatal error Class 'App\Http\Controllers\File' not found, it is almost never an issue with your specific class definition. In fact, if you created a file named File.php inside your App/Http/Controllers directory expecting it to resolve to the global File facade, you have likely run into one of the most common naming collisions in Laravel history.

The root cause is not a missing dependency that requires manual addition to composer.json or config/app.php. The illuminate/filesystem package already contains the necessary code to provide the File facade, and it is included by default when you install the core laravel/framework package. You do not need to list "illuminate/filesystem" separately in your require section unless you are explicitly trying to override or extend the filesystem implementation in a very specific way, which is rarely the right move for standard file operations.

The error message Class 'App\Http\Controllers\File' not found is misleading if taken literally. It suggests that Laravel cannot find the class you defined locally. However, what actually happens when you call File::files() is that the framework's autoloader attempts to resolve the string File via the PSR-4 namespace mapping defined in your composer.json.

Because the global namespace for Illuminate packages is typically Illuminate\Support\Facades, a class named just File does not exist in that namespace. Instead, the Facade system looks for a model or service class that matches the facade name. In Laravel 5, the File facade maps to the Illuminate\Filesystem\FileSystem class (or an alias thereof). The error occurs because your local file at app/Http/Controllers/File.php is shadowing this expectation, and since it doesn't exist or isn't loaded correctly, the autoloader fails to resolve the global alias.

To fix this immediately, you should remove any file named File.php from your App/Http/Controllers directory. This is a critical best practice in Laravel development: never name your controller classes after built-in facades or services. If you need a controller that handles files, name it FileController or CsvHandler. Doing so prevents the autoloader from getting confused between your local implementation and the global framework utilities.

Regarding your configuration changes, adding 'Illuminate\Filesystem\FilesystemServiceProvider' to your providers array in config/app.php is technically redundant for Laravel 5. The framework automatically registers this provider when it loads the core package. Manually adding it will not break anything, but it does not solve the naming collision issue that generated the error in the first place.

Furthermore, ensure your composer.json adheres to standard conventions. You do not need to explicitly require "illuminate/filesystem" if you are using a version of Laravel 5 where filesystem support is bundled within the framework distribution. If you are on an older version of Laravel 5 that required separate installation of illuminate packages, simply running composer update after ensuring the dependencies are correctly listed in require will suffice. The lack of output during composer update often just means the package was already up to date or installed as a dependency of another package (like laravel/framework).

The most robust solution involves cleaning up your namespace usage. Stop treating global facades like local classes. Once you delete the conflicting File.php file and rename your controller appropriately, the call $files = File::files($this->csvDir); will resolve correctly to the Facade wrapper provided by the framework without needing any manual provider registration or composer dependency tweaks.

This pattern of naming a local class after a global helper is a frequent pitfall for developers transitioning from vanilla PHP frameworks to Laravel's facades. The framework relies on strict namespace isolation, and shadowing built-in names breaks that isolation instantly. By respecting these boundaries, you eliminate the need for complex configuration workarounds.

Our network