Hi Fist of all Im Completely New to Laravel i have a function in my Controller like this
public function getSinglePurchase($id){
return DB::table('purchasespayment')
->where("fk_purchases","=",$id)
->orderBy('date', 'desc')->first();
}
public function show($id){
$purchase_info = $this->getSinglePurchase($id);
return view('purchase.view',compact('purchase_info');
}
and when i return this data to view if there is data on return my view is working fine. and when there is no data for example my view file looks like this
{{ purchase_info.amount }}
whenever my controller returns nothing to view i get following error
"Trying to get property 'amount ' of non-object"
I Managed to Fixe that error like following
@if (!empty($purchase_info))
{{ $purchase_info->amount}}
@endif
this method working fine but i have almost 10 to 15 items to get like this do i need to check !empty method everytime or is there any easy way to get or check empty values via Controller. Please Advice