City.php 592 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace App;
  3. use App\Traits\ModelLogChanging;
  4. use Illuminate\Database\Eloquent\Model;
  5. use App\Traits\ModelTimeFormat;
  6. class City extends Model
  7. {
  8. use ModelLogChanging;
  9. use ModelTimeFormat;
  10. use ModelLogChanging;
  11. protected $fillable=[
  12. 'province_id','name','type'
  13. ];
  14. protected $appends=[
  15. 'province_name'
  16. ];
  17. public function province(){
  18. return $this->belongsTo('App\Province','province_id','id');
  19. }
  20. public function getProvinceNameAttribute(){
  21. return $this['province']? $this['province']['name']:null;
  22. }
  23. }