I have a query that works before using laravel eloquent method
$products = Product::where('category', 'ILIKE', '%'.$conditionTxt.'%')
->orderBy('created_at', 'desc')
->get();
But after using query builder approach
$products = DB::table('products')
->where('category', 'ILIKE', '%'.$conditionTxt.'%')
->orderBy('created_at', 'desc')
->get();
It returns this error:
Undefined property: stdClass::$inventory
Here is my model and portion of the view where it points the error.
Model
public function inventory(){
return $this->hasMany('App\InventoryRecord\InventoryRecord');
}
View:
<td>
<?php
for($i = 0; $i < count($val->inventory); $i++){
if( $val->inventory[$i]->total_qty <= 50 ) { ?>
<span style="color:#C00"><?php echo $val->inventory[$i]->total_qty.' -'; ?></span>
<?php }else{ ?>
<span style="color:#25A602"><?php echo $val->inventory[$i]->total_qty.' -'; ?></span>
<?php
}
}
?>
</td>