Why is the image stored in the database? Store it on disk
Dec 6, 2022
5
Level 8
How to return image blob (base64) and strings together from Controller to frontend?
I have an AJAX call that needs to get both array of data (strings) and an image base64 blob:
// From Controller
$data = [];
$details = Model::find($id);
$image = ModelImage::find($image_id);
$data['details'] = $details;
$data['image'] = $image;
return $data;
But I get the following error:
Malformed UTF-8 characters, possibly incorrectly encoded
So I even tried to do:
$data['image'] = mb_convert_encoding($image, 'UTF-8', 'UTF-8');
But then the error becomes:
Method Illuminate\Database\Eloquent\Collection::__toString() must return a string value
How can I return both values (details and blob) from controller then?
Thanks
Please or to participate in this conversation.