Is it possible for Laravel to set default attribute values for model from database, when creating object by new Model
or Model::create()
?
For example, I have table clients
with some columns (name, sex, birthday, device, os, etc). I'm doing
$client = new Client::create(['name' => 'John Doe']);
and want $client
object has all attributes, not only name. dd($client->toArray());
returns
array:1 [▼
"name" => "John Doe",
"id" => 1
]
But dd(Client::find(1)
returns
array:11 [▼
"id" => 1
"name" => "John Doe"
"birthday" => null
"sex" => 1
"device" => ""
"os" => ""
]
Yes, i could set protected $attributes
property in model, but it is not what i'm looking for. I want this to be fetched from database schema.