Last active
February 26, 2019 03:12
-
-
Save shengslogar/d0696ade82bde7d530fb24fdf3dc3e8e to your computer and use it in GitHub Desktop.
Specify a Default Laravel Relationship
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get the author of the post. | |
* @see https://laravel.com/docs/5.7/eloquent-relationships#updating-belongs-to-relationships | |
*/ | |
public function user() | |
{ | |
return $this->belongsTo('App\User')->withDefault([ | |
'name' => 'Guest Author', | |
]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment