Reputation: 2000
i am storing images in storage folder and the url in database but when i want to show them in view they cant be found here is my code :
controller
$filename = $request->file('agreement')->store('public/images');
$client = Client::create([
'title' => $request->title,
'description' => $request->description,
'fax'=>$request->fax,
'adrress1'=>$request->adrress1,
'telephone1'=>$request->telephone1,
'client_type'=>$request->client_type,
'sellpercent'=>$request->sellpercent,
'agreement'=>$filename,
]);
return redirect('admin/client/'.$client->id);
view :
<img src="{{url($client->agreement)}}" alt="some thing">
i tried moving file from storage to the main public folder manually but didnt work even when i put the url on the browser it gives a not found error after that i runned the command
php artisan storage:link
but yet again nothing happens and here is the url i am saving in the database
public/images/KMrCn80Cc9jlNqwLhcSjGM7JJ09lob6cnJGDuTel.jpeg
Upvotes: 0
Views: 694
Reputation: 8287
You have already created symbolic link of storage/app/public
to public/storage
folder using php artisan storage:link
. So, now you only need to upload file using public
disk like this
$filename = $request->file('agreement')->store('subfolder', 'public');
Here physical path of file is at storage/app/public/subfolder
but as you have symbolic link of storage/app/public
to public/storage
. Now you can access it publicly in view using asset
like this
{{asset('storage/subfolder/' . $client->agreement)}}
Upvotes: 1
Reputation: 2469
use asset:
<img src="{{asset($client->agreement)}}" alt="some thing">
and store this path in database :
images/KMrCn80Cc9jlNqwLhcSjGM7JJ09lob6cnJGDuTel.jpeg
Upvotes: 1