mardi 28 mai 2019

laravel 5.8 access other table porpery in on to many relation

i have 3 table

  1. hotel
  2. province
  3. 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