You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Department.php 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Models\Core;
  3. use App\Models\Common\Contact;
  4. use App\Traits\{Blamable, CompanyOwned};
  5. use Database\Factories\Core\DepartmentFactory;
  6. use Illuminate\Database\Eloquent\Factories\{Factory, HasFactory};
  7. use Illuminate\Database\Eloquent\Model;
  8. use Illuminate\Database\Eloquent\Relations\{BelongsTo, HasMany};
  9. use Wallo\FilamentCompanies\FilamentCompanies;
  10. class Department extends Model
  11. {
  12. use Blamable;
  13. use CompanyOwned;
  14. use HasFactory;
  15. protected $table = 'departments';
  16. protected $fillable = [
  17. 'company_id',
  18. 'manager_id',
  19. 'parent_id',
  20. 'name',
  21. 'description',
  22. 'created_by',
  23. 'updated_by',
  24. ];
  25. public function company(): BelongsTo
  26. {
  27. return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id');
  28. }
  29. public function manager(): BelongsTo
  30. {
  31. return $this->belongsTo(Contact::class, 'manager_id');
  32. }
  33. public function parent(): BelongsTo
  34. {
  35. return $this->belongsTo(self::class, 'parent_id');
  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. public function createdBy(): BelongsTo
  46. {
  47. return $this->belongsTo(FilamentCompanies::userModel(), 'created_by');
  48. }
  49. public function updatedBy(): BelongsTo
  50. {
  51. return $this->belongsTo(FilamentCompanies::userModel(), 'updated_by');
  52. }
  53. protected static function newFactory(): Factory
  54. {
  55. return DepartmentFactory::new();
  56. }
  57. }