by default null eloquent user data in relationship in laravel 8 code example
Example: by default null eloquent user data in relationship in laravel 8
# simple handle in blade file
{{ $post->author->name or 'No author' }}
# Model action
public function author()
{
return $this->belongsTo('App\Author')->withDefault();
}
public function author()
{
return $this->belongsTo('App\Author')->withDefault([
'name' => 'Guest Author',
]);
}