Search code examples
phplaravellaravel-filesystemlaravel-6.2

Laravel storage returns FileNotFoundException But file exists


I want read file content in laravel 6, the file already exists but laravel return not found exception.

This is my logs files directory: /var/www/html/myLaravelLab/storage/logs/laravel-2019-10-14.log

$contents = Storage::get(storage_path('logs/laravel-2019-10-14.log'));

Laravel return this error: Illuminate\Contracts\Filesystem\FileNotFoundException

But file already exists!

I want read file contents.


Laravel Version: 6.2.0 - PHP Version: 7.2.19


Solution

  • In config/filesystems.php add new disk logs:

    'disks' => [
            'logs' => [
                'driver' => 'local',
                'root' => storage_path('logs'),
            ],
    // orher disks...
    

    Now you can get log files:

    Storage::disk('logs')->get('laravel-2019-10-14.log');