We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

snapey • 5 years ago

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

Stallyons • 5 years ago

can we use this to delete records ?