Thanks for this. You can specify a new instance of the model and then set an attributes array within the model to declare the default values. This stops the structure of the related model being repeated within the model public function user() { return $this->belongsTo('App\User')->withDefault(new User()); }
//User model
protected attributes=[ 'name' => 'Guest Author' // etc for more ]
You can also use this technique for posts where the user had deleted their account
Thanks for this. You can specify a new instance of the model and then set an attributes array within the model to declare the default values. This stops the structure of the related model being repeated within the model
public function user()
{
return $this->belongsTo('App\User')->withDefault(new User());
}
//User model
protected attributes=[
'name' => 'Guest Author'
// etc for more
]
You can also use this technique for posts where the user had deleted their account