Skip to content
Advertisement

Trying to get property of non-object when trying to select a value from the result

I have a problem with the function. I make a request to select from the database, the selection is normal and there is a second code that should take the value of the price column from the result, but the problem is that I get an error as a result: Trying to get property of non-object.

My code:

JavaScript

If write var_dump($betitem[0]); exit; i received:

JavaScript

How i understand the problem arises because the result is received in an array. But then how to fix this error and get the result from the price column?

Advertisement

Answer

Since $betitem has an object inside an array, you can do

JavaScript

Or you can use the first() method to get the first row matching your conditions.

JavaScript

Also, I can see an extra before DB. You can add use DB; before declaration of your class and it should run just fine. Make sure this DB alias exists in your config/ app.php.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement