Back

Trying to get property of non-object -- No idea where this is coming from, help


lorienhd posted 3 years ago

So i've been coding in a project (in a adding new page of a pagemodule). And suddenly when i went back to the overview page i got this error:

 Trying to get property of non-object (View: /lorien/workbench/modules/page/src/views/overview.blade.php) 
 open: /lorien/app/models/tblroute.php

Now i have no idea where the bug is, and i haven't been coding in the overview part of the module. i Tried to remove all my changes and went back to the part where it did work, but still no change.

Now i know this is not much info for help, but does anyone know how i can figure out where the bug could be?

matthewburrow replied 3 years ago

Comment out the objects that you are trying to access e.g. {{ $variable->name }}, with blade comments {{-- --}} and run through them all including nested views and you will find the culprit :).

Or

dd() all the input sent to the view and find some null data.

lorienhd replied 3 years ago

Ok thanks i'll try those two!

lorienhd replied 3 years ago

matthewburrow said:

Comment out the objects that you are trying to access e.g. {{ $variable->name }}, with blade comments {{-- --}} and run through them all including nested views and you will find the culprit :).

Or

dd() all the input sent to the view and find some null data.

The diedump didn't give me anything unusual, and commenting the objects out didn't change anything. (also tried in the nested views) :(

matthewburrow replied 3 years ago

Well something within the input will be NULL either not them or a property on objects within the input such as models etc.

makzumi replied 3 years ago

This sounds like your object does not exist OR that it is an array...

This adding an "@" infront of the: $yourVar->value; to: @$yourVar->value;

OR

try this:

Change this: {{ $yourVar->value }} To: {{ $yourVar['value'] }}

Hard to tell without seeing any code...

lorienhd replied 3 years ago Solution

Fixed it, after a loooonnnggg search the bug was in the database. Luckely i had a backup :)

Still odd that laravel gave me a complete different error.

matthewburrow replied 3 years ago

lorienhd said:

Fixed it, after a loooonnnggg search the bug was in the database. Luckely i had a backup :)

Still odd that laravel gave me a complete different error.

It gave you the correct error, its just the data that you were trying to access was not there. I.e. from a relationship, if the relationship data does not exist, the attributes on that data would neither exists, leading to 'Trying to get property of non-object.'.

malikali86 replied 10 months ago

Well that solved my problem. Thanks for the suggestions. I am surprised why an array is returned although I did not use toArray() or anything, used just pure \App\Organization::paginate(15).

Thanks.

makzumi said:

This sounds like your object does not exist OR that it is an array...

This adding an "@" infront of the: $yourVar->value; to: @$yourVar->value;

OR

try this:

Change this: {{ $yourVar->value }} To: {{ $yourVar['value'] }}

Hard to tell without seeing any code...

nhatquynh1212 replied 10 months ago

makzumi said:

This sounds like your object does not exist OR that it is an array...

This adding an "@" infront of the: $yourVar->value; to: @$yourVar->value;

OR

try this:

Change this: {{ $yourVar->value }} To: {{ $yourVar['value'] }}

Hard to tell without seeing any code...

I had same error and this solution helps me to pass it. thanks in advanced!

gezzeg replied 9 months ago

makzumi said:

This sounds like your object does not exist OR that it is an array...

This adding an "@" infront of the: $yourVar->value; to: @$yourVar->value;

OR

try this:

Change this: {{ $yourVar->value }} To: {{ $yourVar['value'] }}

Hard to tell without seeing any code...

Thanks for the solution. It help me to. May i know where to read more on this? Thanks!

DCHN04 replied 8 months ago

makzumi said:

This sounds like your object does not exist OR that it is an array...

This adding an "@" infront of the: $yourVar->value; to: @$yourVar->value;

OR

try this:

Change this: {{ $yourVar->value }} To: {{ $yourVar['value'] }}

Hard to tell without seeing any code...

Solved, Thanks :D

sabina2nistor replied 8 months ago

Hello, i have something like this

<p>Posted In:{{ $post->category->name }}</p>

and the error is " Trying to get property of non-object " and i have also populated the database correctly :(

can you please suggest me a solution, thank you

(i have tried with @$post.. but it doesn't display any value)


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us