Property name does not exist on this collection instance

Asked by: frankl79
Date:
Viewed: 629
Answers: 1
  • 0

Hi,
I’m getting this error in my Laravel app when trying to pass data to my view. Here is how I’m trying to do in my controller:

$member = DB::table('users')->orderBy('created_at', 'DESC')->get();

and this is how I’m trying to access it in my blade file

{{ $member->name }}

 

Answers

Answer by: boon

Answered on: 25 Jan 2023

  • 0

When you are using the get() method, you get a collection and not an object so you cannot just access the property like that. If you are using get() first you need to iterate over the collection, then you can get the properties.

Alternatively, you could use find() or first() so you can access the properties the way you tried.

Please log in to post an answer!