$product = Product::where($where)->get();
foreach ($product as $key => $value) {
if ($value->SupplierID) {
$product[$key]['SupplierName'] = Company::find($value->SupplierID)->CompanyName;
} else {
$product[$key]['SupplierName'] = '-';
}
$product[$key]['ProductName'] = $value->getProdNameOne()->ProductName;
}
$relatedcompany = false;
if (!empty(Auth::user())) {
$userid = Auth::user()->id;
$companyfromusers = Companypersonstruct::where('user_id', '=', $userid)->first();
$relatedcompany = array();
if (!empty($companyfromusers->user_id)) {
$companyrelationstruct = CompanyRelationStruct::where('FromCompanyID', '=', $companyfromusers->CompanyID)->get();
if (!empty($companyrelationstruct)) {
foreach ($companyrelationstruct as $crs) {
$relatedcompany[] = Company::find($crs->ToCompanyID);
}
}
}
}