Get the App
SLTechnology News&Howtos  ›  Development  › 

Use withDefault () when associating with Laravel

Shulou Source: shulou.com Published: 2022-06-01 04:38:33 09月22日 Update

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.

Tags: Articles Zhongguan more relevance good practical content articles models knowledge systems errors references help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn macOS Shulou Tech Info Microsoft MariaDB