BalaMurugan08's avatar

how to get image from storage folder and display

I want to display photos from storage folder but the photo is not shown, I have companyregister table, I want to display all my company name with the image they uploaded. I'm new to laravel, I would like to have solution and explanation for this problem.

my travelController

->join('voucherdetails','companyregisters.id','=','voucherdetails.company_id')
 		->join('addvouchers','voucherdetails.id','=','addvouchers.voucher_id')
 		->select('voucherdetails.description','companyregisters.companyName','addvouchers.voucherCode', 'addvouchers.voucherTitle', 'companyregisters.file')
        ->where(['companyregisters.category' => 'Travel'])
 		->get();

my travel.blade.php

<tbody>
			
			@foreach($data as $row)
				<tr>
					<td>{{$row->companyName}}</td>

					<td><img src="storage/app/public/upload/{{ $row->file }}" class="img img-thumbnail"></td>

					<td>{{$row->voucherTitle}}</td>

					<td>{{$row->description}}</td>

					<td>{{$row->voucherCode}}</td>

				</tr>


			@endforeach
		</tbody>

No errors but not displaying did I miss anything or the code is wrong??

0 likes
2 replies
Snapey's avatar
Snapey
Best Answer
Level 122

The image needs to be served from a public folder so that the visitors browser can download it

Ideally you would store the image in your folder /storage/app/public (or a sub folder)

docs;

The storage/app/public directory may be used to store user-generated files, such as profile avatars, that should be publicly accessible. You should create a symbolic link at public/storage which points to this directory. You may create the link using the php artisan storage:link command.

If you follow the above, the link you create in the view should reference the /storage folder

so if you save your images in the PATH /storage/app/public/upload then it will be accessible via the URL /storage/upload

1 like
BalaMurugan08's avatar

Thank You So Much Sir,

I run php artisan storage::link

and I change this

src="storage/upload/{{ $row->file }}"

Please or to participate in this conversation.