Plan.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. public $timestamps = false;
  20. protected static function booted()
  21. {
  22. parent::booted(); // TODO: Change the autogenerated stub
  23. static::addGlobalScope(new CompanyScope);
  24. }
  25. public function requirements()
  26. {
  27. return $this->hasMany(Requirement::class);
  28. }
  29. public function projects()
  30. {
  31. return $this->belongsToMany(Project::class, 'project_plan', 'plan_id', 'project_id');
  32. }
  33. public function children()
  34. {
  35. return $this->hasMany(Plan::class, 'parent_id');
  36. }
  37. public function asset(){
  38. return $this->belongsTo(Asset::class);
  39. }
  40. }