Waybill.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Waybill extends Model
  5. {
  6. protected $fillable=[
  7. 'state','type','waybill_number','owner_id','wms_bill_number','origination','destination','recipient','recipient_mobile','charge','ordering_remark',
  8. 'carrier_id','carrier_bill','origination_city_id','destination_city_id','warehouse_weight','warehouse_weight_unit_id','carrier_weight','carrier_weight_unit_id','carType_id',
  9. 'fee','pick_up_fee','other_fee','collect_fee','dispatch_remark','waybill_price_model_id'
  10. ];
  11. protected $appends=[
  12. 'origination_city_name',
  13. 'carrier_name',
  14. 'owner_name',
  15. 'destination_city_name',
  16. 'warehouse_weight_unit_name',
  17. 'carrier_weight_unit_name',
  18. ];
  19. public function owner(){
  20. return $this->belongsTo('App\Owner','owner_id','id');
  21. }
  22. public function carrier(){
  23. return $this->belongsTo('App\Carrier','carrier_id','id');
  24. }
  25. public function origination_city(){
  26. return $this->belongsTo('App\City','origination_city_id','id');
  27. }
  28. public function destination_city(){
  29. return $this->belongsTo('App\City','destination_city_id','id');
  30. }
  31. public function warehouse_weight_unit(){
  32. return $this->belongsTo('App\Unit','warehouse_weight_unit_id','id');
  33. }
  34. public function carrier_weight_unit(){
  35. return $this->belongsTo('App\Unit','carrier_weight_unit_id','id');
  36. }
  37. public function carType(){
  38. return $this->belongsTo('App\CarType','carType_id','id');
  39. }
  40. public function waybillAuditLogs(){
  41. return $this->hasMany('App\WaybillAuditLog','waybill_id','id');
  42. }
  43. public function getOwnerNameAttribute(){
  44. return $this['owner']? $this['owner']['name']:null;
  45. }
  46. public function getCarrierNameAttribute(){
  47. return $this['carrier']? $this['carrier']['name']:null;
  48. }
  49. public function getOriginationCityNameAttribute(){
  50. return $this['origination_city']? $this['origination_city']['name']:null;
  51. }
  52. public function getDestinationCityNameAttribute(){
  53. return $this['destination_city']? $this['destination_city']['name']:null;
  54. }
  55. public function getWarehouseWeightUnitNameAttribute(){
  56. return $this['warehouse_weight_unit']? $this['warehouse_weight_unit']['name']:null;
  57. }
  58. public function getCarrierWeightUnitNameAttribute(){
  59. return $this['carrier_weight_unit']? $this['carrier_weight_unit']['name']:null;
  60. }
  61. }