0
0

More than 3 years have passed since last update.

Trying to get property of non-objectエラー

Last updated at Posted at 2021-03-07

laravelでビューを作成している際に、Trying to get property of non-objectというエラーが出ました。
これは、アロー演算子の先に値がないというエラーです。

これを解決するには、optional()関数を使います。

{{ optional($post->category)->name }}

ヘルパー関数optional()は第二引数と共に利用し、第一引数(optionalの中)がnullでない時、第二引数を実行します。

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0