City.php 705 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App;
  5. class City extends Model
  6. {
  7. public function getTranslation($field = '', $lang = false){
  8. $lang = $lang == false ? App::getLocale() : $lang;
  9. $city_translation = $this->hasMany(CityTranslation::class)->where('lang', $lang)->first();
  10. return $city_translation != null ? $city_translation->$field : $this->$field;
  11. }
  12. public function city_translations(){
  13. return $this->hasMany(CityTranslation::class);
  14. }
  15. public function country()
  16. {
  17. return $this->belongsTo(Country::class);
  18. }
  19. public function state()
  20. {
  21. return $this->belongsTo(State::class);
  22. }
  23. }