thecelebratedmrk
3 months ago

How to display all files in a directory in my view

Posted 3 months ago by thecelebratedmrk

What I'm trying to do:

My Storage/Images-directory has a lot of images that I want to display as a gallery. Something like:

@foreach($files as $file)

img src="{{$file}}"

@endforeach

I've looked at https://laravel.com/docs/7.x/filesystem#directories already, but haven't had any luck so far.

What I don't understand:

  • Which directory should I point to? Do I use asset() in the same way as when I link to my app.css? Do I link directly to www.mydomain.com/storage/images?
  • Where do I add the $files = Storage::allFiles($directory);

I suspect that I should do something in routes/web.php, app/Http/PagesController.php and a custom view, but I don't know where to add what.

Any help appreciated.

Please sign in or create an account to participate in this conversation.