Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Department.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace App\Models\Core;
  3. use App\Models\User;
  4. use App\Traits\Blamable;
  5. use App\Traits\CompanyOwned;
  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 company(): BelongsTo
  29. {
  30. return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id');
  31. }
  32. public function manager(): BelongsTo
  33. {
  34. return $this->belongsTo(User::class, 'manager_id');
  35. }
  36. public function parent(): BelongsTo
  37. {
  38. return $this->belongsTo(self::class, 'parent_id')
  39. ->whereKeyNot($this->getKey());
  40. }
  41. public function children(): HasMany
  42. {
  43. return $this->hasMany(self::class, 'parent_id');
  44. }
  45. public function employeeships(): HasMany
  46. {
  47. return $this->hasMany(FilamentCompanies::employeeshipModel(), 'department_id');
  48. }
  49. public function createdBy(): BelongsTo
  50. {
  51. return $this->belongsTo(FilamentCompanies::userModel(), 'created_by');
  52. }
  53. public function updatedBy(): BelongsTo
  54. {
  55. return $this->belongsTo(FilamentCompanies::userModel(), 'updated_by');
  56. }
  57. protected static function newFactory(): Factory
  58. {
  59. return DepartmentFactory::new();
  60. }
  61. }