Process.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Process extends Model
  5. {
  6. protected $fillable=[
  7. 'code','owner_id','process_method_id','unit_price','status','remark','amount','completed_amount','created_at','updated_at'
  8. ];
  9. protected $appends=[
  10. 'owner_name','process_method_name',
  11. ];
  12. public function owner(){
  13. return $this->belongsTo('App\Owner','owner_id','id');
  14. }
  15. public function processMethod(){
  16. return $this->belongsTo('App\ProcessMethod','process_method_id','id');
  17. }
  18. public function tutorials(){
  19. return $this->belongsToMany('App\Tutorial','process_tutorial','process_id','tutorial_id');
  20. }
  21. public function processesContents(){
  22. return $this->hasMany('App\ProcessesContent','process_id','id');
  23. }
  24. public function getOwnerNameAttribute()
  25. {
  26. return $this['owner']? $this['owner']['name']:null;
  27. }
  28. public function getProcessMethodNameAttribute()
  29. {
  30. return $this['processMethod']? $this['processMethod']['name']:null;
  31. }
  32. }