Honey Buenavides
Honey Buenavides

Reputation: 23

"Trying to get property of non object" error in Laravel 5.1

I am new to Laravel 5.1 and I'm quite confused why I keep on getting this error. I have tried researching about this problem but nothing seems to solve my problem. It only gives me more errors.

It's really weird since when I try to dd() the variable it returns everything I need.

public function custInfo(Request $request)
{

    $search_custname = $request->input('cust_name');

    $customer_info = \DB::table('tblCustIndividual AS a')
            ->leftJoin('tblJobOrder AS b', 'a.strIndivID', '=', 'b.strJO_CustomerFK')
            ->leftJoin('tblJOPayment AS c', 'b.strJobOrderID', '=', 'c.strTransactionFK')
            ->select('a.strIndivID', \DB::raw('CONCAT(a.strIndivFName, " ", a.strIndivMName, " ", a.strIndivLName) AS fullname'), 'b.*', 'c.*')
            ->where(\DB::raw('CONCAT(a.strIndivFName, " ", a.strIndivMName, " ", a.strIndivLName)'), '=', $search_custname)
            ->first();



    return view('transaction-billingpayment-individual')
            ->with('search_custname', $search_custname)
            ->with('customer_info', $customer_info);
}

here's the screenshot of the dd()

Upvotes: 2

Views: 1035

Answers (1)

Iftikhar uddin
Iftikhar uddin

Reputation: 3192

In your case remove foreach and try to access it like

{{ $customer_info->fullname }}

Or

Try this

if (!$search_custname->isEmpty()){ 
  // your query
}

Actually fisrt() returns Model or null, so always add a check there.

Upvotes: 1

Related Questions