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);
    }



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2MfopTP
via IFTTT

Aucun commentaire:

Enregistrer un commentaire