I am using mass assignment to create a server model like so:
/** @var Model $server */
$server = Server::create($request->all());
return response($server->jsonSerialize(), Response::HTTP_CREATED);
Now my server also has a status
property which maps to a MySQL status
column which has a default value of 0 in MySQL.
Because the status is not being set implicitly in my request attributes(no need since the default is fine) it does not return the status
property on the model. It will return all of the properties in my $request->all()
though. These are validated and coming from a form.
How can I return my full $server
model including the default value for status
? I am forced to fire off another query to re-fetch the model I have just created, just so I can also include the status
property with the MySQL default?