BillingModel.php 1.2 KB

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