I get this error form helper.php. I need sale prices of product. but I get this error.And I dont understand when I get this error.
helper.php
public static function getSalesPriceUsingProductIDCode($id, $customerId)
{
$data = PosCustomerProducts::valid()->where('complete_status',0)->where('customer_id', $customerId)->where('product_id', $id)
->select('product_id', 'sales_price')
->first()->sales_price;
return $data;
}
orderSheetExport.php
if(isset($results[$product->id]))
{
if (Helper::getSalesPriceUsingProductIDCode($product->id,$results['customer_id'])==0)
{
$excel_dynamic_data_values[$index][] = $product->whole_sale_price * $results[$product->id];
$productArray[$rsm_id][$product->id] += $results[$product->id] * $product->whole_sale_price;
$singleProductArray[$rsm_id][$product->id] = $productArray[$rsm_id][$product->id];
}else
{
$excel_dynamic_data_values[$index][] = Helper::getSalesPriceUsingProductIDCode($product->id,$results['customer_id']) * $results[$product->id];
$productArray[$rsm_id][$product->id] += $results[$product->id] * Helper::getSalesPriceUsingProductIDCode( $product->id,$results['customer_id']);
$singleProductArray[$rsm_id][$product->id] = $productArray[$rsm_id][$product->id];
}
}
2
Answers
I solve this problem. I also understand Why I was getting this error. When I use this helper function on a loop. It get some values that were not any sale price data. So it though this error. So, I write if else condition on it.
Helper.php
If you just need the sales_price use
value
functionKindly refer value() in Laravel Queries