WaybillPriceModel.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App\Traits\ModelTimeFormat;
  5. class WaybillPriceModel extends ModelExtended
  6. {
  7. use ModelTimeFormat;
  8. protected $fillable=[
  9. 'logistic_id','province_id','city_id','unit_id','range_min','range_max','unit_price','base_fee','initial_weight'
  10. ];
  11. protected $appends=[
  12. 'carrier_name',
  13. 'province_name',
  14. 'city_name',
  15. 'unit_name',
  16. ];
  17. public function logistic(){
  18. return $this->belongsTo('App\Logistic','logistic_id','id');
  19. }
  20. public function province(){
  21. return $this->belongsTo('App\Province','province_id','id');
  22. }
  23. public function city(){
  24. return $this->belongsTo('App\City','city_id','id');
  25. }
  26. public function unit(){
  27. return $this->belongsTo('App\Unit','unit_id','id');
  28. }
  29. public function getCarrierNameAttribute(){
  30. return $this['carrier']? $this['carrier']['name']:null;
  31. }
  32. public function getProvinceNameAttribute(){
  33. return $this['province']? $this['province']['name']:null;
  34. }
  35. public function getCityNameAttribute(){
  36. return $this['city']? $this['city']['name']:null;
  37. }
  38. public function getUnitNameAttribute(){
  39. return $this['unit']? $this['unit']['name']:null;
  40. }
  41. }