lundi 29 août 2016

Laravel 5.1 returns null text values as string "null"

I'm using Laravel 5.1 and have a Eloquent query that gets values from a mysql database, and when the textfields are NULL in the database, they come back as "null" in the json. I would like them to come back as null (not a string, just null). Is there an easy way to do this for any (or all) values in the database, or do I have to write an accessor for every field I want this applied to?

Just to reiterate/demonstrate, the json currently comes back as this:

{
  id : 1,
  first : "jason",
  last  : "null"
}

And I'd like it to be like this instead

{
  id : 1,
  first : "jason",
  last  : null
}

The mysql field last is declared as varchar, allow null, default null.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire