vendredi 27 avril 2018

Laravel 5.0 Eloquent 3rd level relationships

i have three tables

Property:

  1. property_id
  2. title

Property Prices:

  1. property_price_id
  2. currency_id
  3. price

currencies

  1. currency_id
  2. title

Property Model:

public function PropertyPrice(){
    return $this->hasMany('App\PropertyPrice','property_id');
}

property Price Model:

 public function Currency(){

         return $this->belongsTo('App\Currency','currency_id');  
}

 public function Property(){

       return $this->belongsTo('App\Property','property_id');
}

Currency Model

public function PropertyPrice(){

  return $this->hasMany('App\PropertyPrice','currency_id');
}

Now i am running this Eloquent command for getting properties with prices,

Property::with('PropertyPrice')->orderBy('ordering','desc')->paginate(10);

but i am confused how to get the currency title? please note i have seen the example provided on official documentation under "Has Many Through" but its a different example , i am unable to relate to it.

please help, thanks



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2FlE5Mr
via IFTTT

Aucun commentaire:

Enregistrer un commentaire