Use withDefault () when associating with Laravel
This article will explain in detail how to use withDefault () when you relate to Laravel. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Use withDefault () when associating
When calling the association, if another model does not exist, the system throws a fatal error, such as $comment- > post- > title, then we need to use withDefault ()
... public function post () {return $this- > belongsTo (App\ Post::class)-> withDefault ();} this is the end of this article on "how to use withDefault () in Laravel association". I hope the above content can be helpful to you so that you can learn more knowledge. if you think the article is good, please share it for more people to see.