Sarath TS
Sarath TS

Reputation: 2462

How can get files from inner folder of storage in laravel 5.5?

I need to list files from storage->app->public->huetten->it contains 17 folders. Each folder contains images. Any help would be appreciated.

public function show($id)
    {
        if(!empty($id)) {
            $directories = Storage::disk('public')->allDirectories('huetten');
            foreach ($directories as $directory) {
                //dd($directory); // Here i get huetten/folder1

                $files = Storage::files($directory);
                foreach ($files as $file) {
                    dd($file); // But here files are not listing
                }


            }
        }
    }

Upvotes: 3

Views: 5833

Answers (1)

Oluwafemi Sule
Oluwafemi Sule

Reputation: 38952

Storage uses the default Filesystem disk in config/filesystems.php which is set to local (i.e storage/app/) in a fresh Laravel project.

I assume that it is set to this same value in your project.

You want to list files in storage/app/public, and this corresponds to the public disk in config/filesystems.php.

In your loop, you can correctly the search directory by getting a Filesystem instance that for the public disk like you already do when listing the directories.

$files = Storage::disk('public')->files($directory);
/* [ 'storage/app/public/huetten/folder1/foo', 'storage/app/public/huetten/folder1/bar', ...] */

Upvotes: 7

Related Questions