Search code examples
phplinuxlaravelstoragelaravel-10

In Laravel how to display the the image files from storage/app/ and display?


I created the laravel project and the problem is that the admin users are filling the form along jpg file and the file is being uploaded and being stored in storage directory but where the image aim to be displayed to public users it is not being displayed.

{{url('/storage/app/news/' . $val2->id . '.png') }}"

Although the file exists at that locations.

I tried with changing the file reading mode permission for server.

I have not moved to deployment phase although, the issue is in Laravel development server.

The file is not being displayed at web while file is there don't know access issue or what else.


Solution

  • Couple of ideas! You might want to make sure you've run php artisan storage:link to make a symbolic link between where your files are being uploaded and where you want to access them in the application.

    You also might want to use Laravel's storage_path() helper function in conjunction with asset() rather than url(). This should guarantee that you're always accessing files within your storage directory. So your code would look like:

    "{{ asset(storage_path('app/news/' . $val->id . '.png')) }}"
    

    There's a few notes on this in the Laravel docs if you want to check it out.