loading...

Trying To Get Property Of Non-Object In Laravel

pakainfocom profile image pakainfo ・1 min read

Is your query returning array or object? If you dump it out, you might find that it's an array and all you need is an array access ([]) instead of an object access (->).

If you working with or loops (for, foreach, etc.) or relationships (one to many, many to many, etc.), this may mean that one of the queries is returning a null variable or a null relationship member.

For example:

In a table, you may want to list users with their roles.


    @foreach
 ($users as $user)
 
        $user->name 
         $user->role->name 
  
    @endforeach

More Solution:

Discussion

pic
Editor guide