SupportTicket.php 4.7 KB

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