Property name does not exist on this collection instance


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 }}

Answer ( 1 )


    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.

Leave an answer