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.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Models\Core;
  3. use App\Models\Common\Contact;
  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, CompanyOwned, HasFactory;
  16. protected $table = 'departments';
  17. protected $fillable = [
  18. 'company_id',
  19. 'manager_id',
  20. 'parent_id',
  21. 'name',
  22. 'description',
  23. 'created_by',
  24. 'updated_by',
  25. ];
  26. public function company(): BelongsTo
  27. {
  28. return $this->belongsTo(FilamentCompanies::companyModel(), 'company_id');
  29. }
  30. public function manager(): BelongsTo
  31. {
  32. return $this->belongsTo(Contact::class, 'manager_id');
  33. }
  34. public function parent(): BelongsTo
  35. {
  36. return $this->belongsTo(self::class, 'parent_id');
  37. }
  38. public function children(): HasMany
  39. {
  40. return $this->hasMany(self::class, 'parent_id');
  41. }
  42. public function employeeships(): HasMany
  43. {
  44. return $this->hasMany(FilamentCompanies::employeeshipModel(), 'department_id');
  45. }
  46. public function createdBy(): BelongsTo
  47. {
  48. return $this->belongsTo(FilamentCompanies::userModel(), 'created_by');
  49. }
  50. public function updatedBy(): BelongsTo
  51. {
  52. return $this->belongsTo(FilamentCompanies::userModel(), 'updated_by');
  53. }
  54. protected static function newFactory(): Factory
  55. {
  56. return DepartmentFactory::new();
  57. }
  58. }