vendredi 20 mai 2016

Laravel Eloquent Relationship Output Related Through

I have the following models

REP

public function orders()
    {
        return $this->hasMany('App\Order', 'REP', 'REPID');
    }

ORDER

public function customer()
    {
        return $this->hasOne('App\Customer', 'CUCODE', 'ACCOUNTCODE');
    }

In my controller I am returning a collection to my view

$rep = REP::where('user','wolrab')->first();

which in my view I use like the following

@foreach($rep->orders as $order)
   <tr>
       <td></td>
       <td></td>
   </tr>
@endforeach

In the output I'm trying to call the customername from the customer relationship but I get a error:

Trying to get property of non-object

If I

dd($order->customer)

I can see the related customer but I just cant output just the name!

Can anyone see what I'm doing wrong?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire