Department.php 690 B

1234567891011121314151617181920212223242526272829303132333435
  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. class Department extends Model
  8. {
  9. use HasFactory,Filterable;
  10. protected $table = 'department';
  11. protected $fillable = [
  12. 'name',
  13. 'parent_id',
  14. 'company_id',
  15. 'manager_id',
  16. ];
  17. protected static function booted()
  18. {
  19. parent::booted(); // TODO: Change the autogenerated stub
  20. static::addGlobalScope(new CompanyScope);
  21. }
  22. public function children()
  23. {
  24. return $this->hasMany(Department::class, 'parent_id');
  25. }
  26. }