You can assign a default model in belongsTo
relationship, to avoid fatal errors when calling it like {{ $post->user->name }}
if $post->user doesn't exist.
1public function user()2{3 return $this->belongsTo('App\User')->withDefault();4}
You can assign a default model in belongsTo
relationship, to avoid fatal errors when calling it like {{ $post->user->name }}
if $post->user doesn't exist.
1public function user()2{3 return $this->belongsTo('App\User')->withDefault();4}