I need help, I want assistance with my api, I want to return an image if its available on the database or return null if no value on db.
Th is is my resource code
return [
'id' => $this->id,
'name' => $this->name,
'photo' => isset($this->photo) ? url('/storage',$this->photo) : "",
];
Here is my json that is returns
"data": [
{
"id": 1,
"name": "Public Safety",
"photo": "https://xxxxxxxxxxxxx/storage"
},
{
"id": 2,
"name": "Severe / Extreme Weather",
"photo": "https://xxxxxxxxxxxxx/storage"
},
I want it to return photo data only if there is a value on db column, if nothing is there then return null.
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3975WQ3
via IFTTT
Aucun commentaire:
Enregistrer un commentaire