'datetime:Y-m-d', ]; protected $fillable = ['products_id','commission_date','commission_earned']; public function products() { return $this->belongsTo(Product::class); } public function productNameCommission($productId){ $productName = 'N/A'; $companyName = 'No Company Assigned'; if(AlternativeInvestmentFund::where('products_id',$productId)->exists()){ $aif = AlternativeInvestmentFund::where('products_id',$productId)->first(); $productName = $aif->fund_name; $companyName = $aif->companies_id?Company::where('id',$aif->companies_id)->value('company_name'):'No Company Assigned'; } if(FractionalRealEstate::where('products_id',$productId)->exists()){ $fre = FractionalRealEstate::where('products_id',$productId)->first(); $productName = $fre->property_name_and_location; $companyName = $fre->companies_id?Company::where('id',$fre->companies_id)->value('company_name'):'No Company Assigned'; } return [ 'product_name' => $productName, 'company_name' => $companyName ]; } }