mercredi 23 janvier 2019

Laravel pivot table relational data not retrieve

I have four table.

country
----------
id,name

service
----------
id,name

country_service
----------
id,country_id,service_id

country_service_rate
----------
id,country_service_id,rate

Now I want to get value of country_service_rate table row.

country_service model

public function rate(){
    return $this->belongsTo('App\CountryServiceRate');
}

Service Model

public function country(){
    return $this->belongsToMany(Country::class)->withPivot('id','is_base');
}

When I am trying to get data of pivot table related

$country->pivot->rate

getting null. But $country->pivot showing country_service table row data.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire