Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

Department.php 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Models\Core;
  3. use App\Concerns\Blamable;
  4. use App\Concerns\CompanyOwned;
  5. use App\Models\User;
  6. use Database\Factories\Core\DepartmentFactory;
  7. use Illuminate\Database\Eloquent\Factories\Factory;
  8. use Illuminate\Database\Eloquent\Factories\HasFactory;
  9. use Illuminate\Database\Eloquent\Model;
  10. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  11. use Illuminate\Database\Eloquent\Relations\HasMany;
  12. use Wallo\FilamentCompanies\FilamentCompanies;
  13. class Department extends Model
  14. {
  15. use Blamable;
  16. use CompanyOwned;
  17. use HasFactory;
  18. protected $table = 'departments';
  19. protected $fillable = [
  20. 'company_id',
  21. 'manager_id',
  22. 'parent_id',
  23. 'name',
  24. 'description',
  25. 'created_by',
  26. 'updated_by',
  27. ];
  28. public function manager(): BelongsTo
  29. {
  30. return $this->belongsTo(User::class, 'manager_id');
  31. }
  32. public function parent(): BelongsTo
  33. {
  34. return $this->belongsTo(self::class, 'parent_id')
  35. ->whereKeyNot($this->getKey());
  36. }
  37. public function children(): HasMany
  38. {
  39. return $this->hasMany(self::class, 'parent_id');
  40. }
  41. public function employeeships(): HasMany
  42. {
  43. return $this->hasMany(FilamentCompanies::employeeshipModel(), 'department_id');
  44. }
  45. protected static function newFactory(): Factory
  46. {
  47. return DepartmentFactory::new();
  48. }
  49. }