City.php 506 B

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