mercredi 22 janvier 2020

Hide attribute in Laravel API Resource if db field is null

I would like to hide an api resource attribute if it returns null.

Situation

I have a an api that pulls tickets from db , some logged tickets have images and some have no images.

In the front end when pulling data from json, I get application url string only since there is no data from db photo column.

I am using this code in my api resource to get the full image url.

'photo' => asset($this->photo),


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire