Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel - Image saved in storage folder not showing to user

I have this code to save an image in the storage/app/uploads folder

 $image_main = Image::where('property_id', $id)->get();

$file = $request->file('file');
      $destinationPath = 'uploads';
      $i = 0;
      foreach ($file as $file1) {
          $i++;
          $extension = $file1->getClientOriginalExtension();
          $path = $file1->storeAs(
              $destinationPath, $i.time().".".$extension
          );

This is my blade file

@foreach ($image_main as $images)
        <img src="{{"/storage/app/".$images->filename}}

The file saves in the storage/app/uploads folder but it doesn't show to the user, it says file not found. am I to set anything in the filesystems.php file

like image 904
Adokiye Iruene Avatar asked May 17 '18 15:05

Adokiye Iruene


People also ask

How to display the storage folder image in Laravel?

This tutorial is for How to display the storage folder image in Laravel? I would like to display an image saved in a storage directory. Laravel default provides storage:link command. this command is to use the storage folder created in your root directory. The Laravel storage app directory is more robust and secure.

Where can I find the file system configuration in Laravel?

Laravel's filesystem configuration file is located at config/filesystems.php. Within this file, you may configure all of your filesystem "disks". Each disk represents a particular storage driver and storage location.

How to symlink Laravel storage to public directory?

Laravel storage filesystem is so unique. When you doing any upload it will upload in the storage/app/public directory. To make it accessible in public directory, things need to do is create symlink by run command: This command will symlinked storage/app/public to public/storage

Can I switch between local and production storage options in Laravel?

Even better, it's amazingly simple to switch between these storage options between your local development machine and production server as the API remains the same for each system. Laravel's filesystem configuration file is located at config/filesystems.php.


2 Answers

Laravel storage filesystem is so unique. When you doing any upload it will upload in the storage/app/public directory. To make it accessible in public directory, things need to do is create symlink by run command:

php artisan storage:link

This command will symlinked storage/app/public to public/storage

Just follow the documentation about how to put and how to retrieve the file url. I am pretty sure the step you are missing is creating the symlink.

Hope it helps.

like image 58
Dharma Saputra Avatar answered Sep 23 '22 16:09

Dharma Saputra


Your storage folder is not accessible from user.

You must pass by Storage::url() method:

Storage::url("/storage/app/{$images->filename}")

As:

<img src="{{ Storage::url("/storage/app/{$images->filename}") }}" alt="{{ $images->filename }}" />

https://laravel.com/docs/master/filesystem#retrieving-files

like image 45
pirmax Avatar answered Sep 19 '22 16:09

pirmax