vendredi 16 novembre 2018

Laravel Model Create method retuns incomplete fields model instance

I am having an issue retrieving my model data after insertion. Below is a sample code in which User model has already its $fillable containing all needed attributes (id and state attributes as extra to the below ones).

$values = ['firstname' => 'Nick', 'lastname' => 'King', 'gender' => 'male' ];
$createdUser = User::create( $values );

When sending back the $createdUser as JSON, I noticed that the state attribute doesn't exists. It does exists in the migration having a default value and also in the model $fillable but not in the $hidden attribute. So what's wrong?

Is that a bug for not having fields inserted with their default values in the returned model or it's just the way Laravel works.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire