Process.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Process extends Model
  5. {
  6. protected $fillable=[
  7. 'code','owner_id','bill_type','wms_code','process_method_id','operation_code',
  8. 'unit_price','status','commodity_id','amount','completed_amount','remark','created_at','updated_at'
  9. ];
  10. protected $appends=[
  11. 'owner_name','process_method_name','commodity_name','commodity_barcode'
  12. ];
  13. public function owner(){
  14. return $this->belongsTo('App\Owner','owner_id','id');
  15. }
  16. public function processMethod(){
  17. return $this->belongsTo('App\ProcessMethod','process_method_id','id');
  18. }
  19. public function commodity(){
  20. return $this->belongsTo('App\Commodity','commodity_id','id');
  21. }
  22. public function tutorials(){
  23. return $this->belongsToMany('App\Tutorial','process_tutorial','process_id','tutorial_id');
  24. }
  25. public function getOwnerNameAttribute()
  26. {
  27. return $this['owner']? $this['owner']['name']:null;
  28. }
  29. public function getProcessMethodNameAttribute()
  30. {
  31. return $this['processMethod']? $this['processMethod']['name']:null;
  32. }
  33. public function getCommodityNameAttribute()
  34. {
  35. return $this['commodity']? $this['commodity']['name']:null;
  36. }
  37. public function getCommodityBarcodeAttribute()
  38. {
  39. return $this['commodity']? $this['commodity']['barcode']:null;
  40. }
  41. }