You can send it in url form i think it's best.
protected $appends = [
'image',
];
public function getImageAttribue()
{
$image_name ='abc.png';
return storage_path('app/images/'.$image_name);
}
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello everyone. I have the following case: There are bunch of images stored in storage/app/images folder in Lumen API. Their path including unique name is stored in the DB. I want when the model instance to which each image is attached is send to the Angular FE to send the image itself so I can display it. I had the idea of making a custom attribute function inside the model and then use the protected $appends array to attach the image to the data I am sending. But cant get my head around how do i get the image itself and in what form should i send it? Any advice will be greatly appreciated.
I changed the location in the storage app (did not do a symlink tbh). Then i came up with the following code and it works fine atm:
final public function getContentAttribute(): string
{
$fullPath = storage_path() . '/app/public/favicons/' . $this->hash . '.png';
try {
return base64_encode(File::get($fullPath));
} catch (FileNotFoundException $e) {
return '';
}
}
Please or to participate in this conversation.