Laravel's Storage::Files not finding my files

i wanted to count how many images are in a storage directory but it seems that Storage::Files not finding any of them, i've stored 4 images in storage\app\public\property\*id_of_the_property* and i've already excuted php artisan storage:link and the link are working perfectly, at least at first glance.

Here is my config\FilesSystems.php

'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

        's3' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
        ],

    ],

And my controler :

public function show($id)
    {

        $show = [];    
        $directory = 'property/'.$id;
        $files = Storage::Files($directory);
        $count = count($files);

        $show['count'] = $count;
        $show['directory'] = $directory;

        return $show;
    }

But the the variable $show['count'] is displaying 0 when it should be 4 and the Storage::Files are not doing any thing since $show['directory'] are showing "property/1" and 1 is the id that i'm testing with. What am i missing?

i've tryed using :

$directory = Storage::url('property/'.$id);
/* Result "/storage/property/1" */
$directory = Storage::url('app/public/property/'.$id);
/* Result "/storage/app/public/property/1" */

or

$directory = Storage_path('property\\'.$id);
/* Result "D:\\xampp\\htdocs\\www\\APP\\storage\\property\\1" */
$directory = Storage_path('app/public/property/'.$id);
/* Result "D:\\xampp\\htdocs\\www\\APP\\storage\\app\\public\\property\\1" */

but no success too, the count are still 0.

Thank you for the help.

728x90

2 Answers Laravel's Storage::Files not finding my files

you can use File facade

use Illuminate\Support\Facades\File;
...
$images = File::allFiles(storage_path('app/public/property')); // this is recursive

or

$images = File::files(storage_path('app/public/property/'.$id)); // this is NOT recursive

4 months ago

Use public_path($directory); for this

4 months ago