by default null eloquent user data in relationship in laravel 8

Solutions on MaxInterview for by default null eloquent user data in relationship in laravel 8 by the best coders in the world

showing results for - "by default null eloquent user data in relationship in laravel 8"
Salomé
13 Oct 2017
1# simple handle in blade file 
2{{ $post->author->name or 'No author' }}
3
4# Model action 
5public function author()
6{
7    return $this->belongsTo('App\Author')->withDefault();
8}
9
10public function author()
11{
12    return $this->belongsTo('App\Author')->withDefault([
13        'name' => 'Guest Author',
14    ]);
15}
16
17