WaybillPriceModel.php 1.3 KB

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