SupportTicket.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. /**
  6. * @property int $id
  7. * @property int|null $unit_id
  8. * @property int $applicant_user_id
  9. * @property int|null $responsable_user_id
  10. * @property int|null $student_id
  11. * @property string $title
  12. * @property string|null $description
  13. * @property string $severity
  14. * @property \Illuminate\Support\Carbon|null $created_at
  15. * @property \Illuminate\Support\Carbon|null $updated_at
  16. * @property string|null $deleted_at
  17. * @property string|null $scope
  18. * @property string|null $sector
  19. * @property string $status
  20. * @property string $origin
  21. * @property int|null $applicant_unit_id
  22. * @property int|null $target_unit_id
  23. * @property string|null $batch_id
  24. * @property-read \App\Models\Unit|null $applicantUnit
  25. * @property-read \App\Models\User $applicantUser
  26. * @property-read \App\Models\User|null $responsableUser
  27. * @property-read \App\Models\Unit|null $targetUnit
  28. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket newModelQuery()
  29. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket newQuery()
  30. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket query()
  31. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket visibleToUnit(int $unitId)
  32. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereApplicantUnitId($value)
  33. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereApplicantUserId($value)
  34. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereBatchId($value)
  35. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereCreatedAt($value)
  36. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereDeletedAt($value)
  37. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereDescription($value)
  38. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereId($value)
  39. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereOrigin($value)
  40. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereResponsableUserId($value)
  41. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereScope($value)
  42. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereSector($value)
  43. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereSeverity($value)
  44. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereStatus($value)
  45. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereStudentId($value)
  46. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereTargetUnitId($value)
  47. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereTitle($value)
  48. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereUnitId($value)
  49. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereUpdatedAt($value)
  50. * @mixin \Eloquent
  51. */
  52. class SupportTicket extends Model
  53. {
  54. use HasFactory;
  55. protected $table = 'support_tickets';
  56. protected $guarded = [
  57. 'id', // Add more fields that shouldn't be edited here
  58. ];
  59. protected $casts = [
  60. 'created_at' => 'datetime',
  61. 'updated_at' => 'datetime',
  62. // Add your casts here (e.g., 'is_active' => 'boolean')
  63. ];
  64. // Relationships
  65. public function applicantUnit()
  66. {
  67. return $this->belongsTo(\App\Models\Unit::class, 'applicant_unit_id');
  68. }
  69. public function targetUnit()
  70. {
  71. return $this->belongsTo(\App\Models\Unit::class, 'target_unit_id');
  72. }
  73. public function applicantUser()
  74. {
  75. return $this->belongsTo(\App\Models\User::class, 'applicant_user_id');
  76. }
  77. public function responsableUser()
  78. {
  79. return $this->belongsTo(\App\Models\User::class, 'responsable_user_id');
  80. }
  81. // Query Scopes
  82. public function scopeVisibleToUnit($query, int $unitId)
  83. {
  84. return $query->where(function ($q) use ($unitId) {
  85. $q->where('target_unit_id', $unitId)
  86. ->orWhere('applicant_unit_id', $unitId);
  87. });
  88. }
  89. }