I want to display images in my Laravel Orchid admin panel. Orchid stores the uploaded images in this folder, with the folder name being the date it was uploaded:
storage\app\public\2021\04\21\<name>
Laravel stores the image original name, path, extension etc in a special table called 'attachments'. It is linked to my main table called 'users' by an id, image_id in 'users' and id in 'attachments'. In my database, the path is stored as the date, e.g:
2021/04/21/
I did this SQL join query to retrieve the image:
$image = $user->image_id;
$images = DB::table('users')
->leftJoin('attachments', 'users.image_id', '=', 'attachments.id')
->where('users.image_id', '=', $image)
->get(['name', 'original_name', 'path', 'extension']);
foreach($images as $image)
{
$image_url = $image->path.$image->name.'.'.$image->extension;
return "<img src='{$image_url}'
<span class='small text-muted mt-1 mb-0'>{$image->original_name}</span>";
}
I can display the original name however the image does not display. I would like to know if there is anything wrong with the way i retrieved the image. Thank you.
<imgtag is missing a closing>, and it might need a size (width and height)?>and i think you're missing your project root in your url. it should be something like this:127.0.0.1:8000/publc/path/to/folder/adminpart, it ishttp://127.0.0.1:8000/storage/2021/04/12/12876b4a034032120b0a3cc3972f19cf2411aaaf.png. I kinda need some guidance here. do i need to register the picture route under/admin?