Forum

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

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?

lorienhd
lorienhd
  • 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.

Ok thanks i'll try those two!

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) :(

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

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

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.

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.'.

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

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!

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!

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

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)