Plan.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Models;
  3. use App\Models\Scopes\CompanyScope;
  4. use EloquentFilter\Filterable;
  5. use Illuminate\Database\Eloquent\Factories\HasFactory;
  6. use Illuminate\Database\Eloquent\Model;
  7. use Illuminate\Database\Eloquent\SoftDeletes;
  8. class Plan extends Model
  9. {
  10. use HasFactory, Filterable,SoftDeletes;
  11. protected $fillable = [
  12. 'title',
  13. 'asset_id',
  14. 'parent_id',
  15. 'begin',
  16. 'end',
  17. 'description',
  18. ];
  19. protected static function booted()
  20. {
  21. parent::booted(); // TODO: Change the autogenerated stub
  22. static::addGlobalScope(new CompanyScope);
  23. }
  24. public function requirements()
  25. {
  26. return $this->hasMany(Requirement::class);
  27. }
  28. public function projects()
  29. {
  30. return $this->belongsToMany(Project::class, 'project_plan', 'plan_id', 'project_id');
  31. }
  32. public function children()
  33. {
  34. return $this->hasMany(Plan::class, 'parent_id');
  35. }
  36. public function asset(){
  37. return $this->belongsTo(Asset::class);
  38. }
  39. }