i have 3 table
- hotel
- province
- city
hotel have relation to city and city have relation to province. city id will save in city filed in hotel table. how can i access city name and province name in Hotel model?
in hotel model i wrote this :
public function city(){
return $this->belongsTo(City::class);
}
and in city model i have this:
public function hotel(){
return $this->hasMany(Hotel::class);
}
public function province(){
return $this->belongsTo(Province::class);
}
and in province
public function cities(){
return $this->hasMany(City::class);
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire