Rename it to getFirstImageAttribute.
Jan 11, 2021
15
Level 4
Accessors not working in API
I have created an accessor to modify a database value
public function getImage1Attribute($value)
{
return $value ? asset('storage/hosts/images/' . $value) : null;
}
but I am still getting original value in JSON API like this
{
"message": "success",
"data": {
"id": 1,
"image_1": "n0rVxA1L-1610381013.jpg",
"created_at": "2021-01-07 18:02:56",
"updated_at": "2021-01-11 16:03:33"
}
}
I am passing response like this
return response([
'message' => Lang::get('api.success'),
'data' => HostDetail::find($id)
]);
I am not getting this problem with other models
I found out that the problem is with the column name image_1 but laravel is considering as image1. Is there any way around this?
Please or to participate in this conversation.