Reputation: 301
I'm using The Public Disk
which is local driver. I create a symbolic link from public/storage
to storage/app/public
using this given command php artisan storage:link
. I didn't change anything as mentioned in laravel filesystem documentation. But i'm not able to view the image with asset
helper. File_path
is storing in database but still images are broken.
Controller:
public function store(Request $request)
{
$this->validate($request, [
'title' => 'required',
'file' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
$slide = new Slider();
$slide->title = $request->title;
$slide->description = $request->description;
//uploading image
if ($request->hasFile('file')) {
$file = $request->file('file');
$slide->file_name = str_random(40) . $file->getClientOriginalName();
$slide->file_size = $file->getClientSize();
$slide->file_mime = $file->getClientMimeType();
$slide->file_path = $file->storeAs('public', $slide->file_name);
}
$slide->status = $request->status;
$slide->save();
return redirect()->route('slider.index')->with('success', 'Done');
}
I'm using storeAs
method, which receives the path, the file name.
View:
<td><img src="{{ asset($slide->file_path) }}" class="content" width="25"></td>
StoreAs
method returns the path which is public/filename.jpg
and images store into public/storage
folder. How do i view the images?
Upvotes: 0
Views: 459
Reputation: 40653
The public and S3 storages support the url
method that you can use to get the correct URL for the image
<td><img src="{{ Storage::url($slide->file_path) }}" class="content" width="25"></td>
Upvotes: 1
Reputation: 1537
You should add storage prefix to your asset:
<td><img src="{{ asset('storage/' . $slide->file_path) }}" class="content" width="25"></td>
Upvotes: 0