1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Laravelでエラー「Trying to get property 〜 of non-object」が出た時の対処法

Last updated at Posted at 2021-01-28

#問題

Trying to get property 'name' of non-object

オブジェクトにnameというプロパティがないということを言っています。
つまりこれは存在しない変数のプロパティやnullの値を参照した時に発生するもののようです。

#解決法

{{ $user->name ?? "名無しさん" }}

プロパティに値が入っていた場合の変数(値)だけでなく、??の後にプロパティがnullだった場合の変数(値)を記述して用意しておくことで解決できます。

1
0
0

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?