Good afternoon, I am making a website on e-commerce. And it allows me to add products and everything.
But when I want to see my product list in admin panel and main page, I get two errors.
Trying to get property 'status' of non-object (View: C:\xampp\htdocs\Aplicaciones Web Para I4.0\Tecnologia Express\resources\views\frontEnd\index.blade.php)
Code where the error is marked
<?php if($product->category->status==1): ?>
Trying to get property 'name' of non-object (View: C:\xampp\htdocs\Aplicaciones Web Para I4.0\Tecnologia Express\resources\views\backEnd\products\index.blade.php)
Code where the error is marked
<td style="vertical-align: middle;"><?php echo e($product->p_name); ?></td>
<td style="vertical-align: middle;"><?php echo e($product->category->name); ?></td>
I also attach the screenshots
Kevin,
Both of those errors mean that properties that you are trying to access can't be accessed because the object on which you are trying to access them is null
or non-existent. So, for the first screenshot in blade
file you probably don't have $product
variable available, or on $product
(if it is available) category
is not defined.
In the second screenshot $product->category
is not available again, which probably means that on $product
you don't have category
available.
Make sure you are providing category
together with $product
from the controller.
You can do something like $products->with('category')
. Also, to debug if you have or don't have category
on the product try doing {{ dd($product) }}
in your blade
file and see what is available on $product
.