Beginner_Hello
Beginner_Hello

Reputation: 367

In Laravel, how can I access all files inside of the storage directory?

I have a Laravel application with a storage/app/icons directory, inside of which is about 200 files/images:

enter image description here

My method to get retrieve all files inside of this folder is:

    public function index()
    {
        $icons = public_path('icons');
        $allIconsInsideFolder = Storage::allFiles($icons);
        return view('instapage', compact('allIconsInsideFolder'));
    }

However, it doesn't work correctly. How can I change the controller function so that it retrieves all files inside of the storage/app/icons directory?

Upvotes: 0

Views: 2641

Answers (1)

OMR
OMR

Reputation: 12188

you should pass the right path to the Storage::allFiles() method, witch look like it is in storage path in app folder then icons folder

please try:

$icons = storage_path('app/icons');
$allIconsInsideFolder = Storage::allFiles($icons);

or:

$icons = storage_path('app/icons');
$allIconsInsideFolder = File::files($icons);

or

  $icons = storage_path('app/icons');
    $allIconsInsideFolder = scandir($icons);

it should work

Upvotes: 2

Related Questions