SupportTicket.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 $unit_id
  8. * @property int $applicant_user_id
  9. * @property int $responsable_user_id
  10. * @property int $student_id
  11. * @property string $title
  12. * @property string|null $description
  13. * @property int $support_status_id
  14. * @property string $severity
  15. * @property \Illuminate\Support\Carbon|null $created_at
  16. * @property \Illuminate\Support\Carbon|null $updated_at
  17. * @property string|null $deleted_at
  18. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket newModelQuery()
  19. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket newQuery()
  20. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket query()
  21. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereApplicantUserId($value)
  22. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereCreatedAt($value)
  23. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereDeletedAt($value)
  24. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereDescription($value)
  25. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereId($value)
  26. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereResponsableUserId($value)
  27. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereSeverity($value)
  28. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereStudentId($value)
  29. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereSupportStatusId($value)
  30. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereTitle($value)
  31. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereUnitId($value)
  32. * @method static \Illuminate\Database\Eloquent\Builder<static>|SupportTicket whereUpdatedAt($value)
  33. * @mixin \Eloquent
  34. */
  35. class SupportTicket extends Model
  36. {
  37. use HasFactory;
  38. protected $table = 'support_tickets';
  39. protected $guarded = [
  40. 'id', // Add more fields that shouldn't be edited here
  41. ];
  42. protected $casts = [
  43. 'created_at' => 'datetime',
  44. 'updated_at' => 'datetime',
  45. // Add your casts here (e.g., 'is_active' => 'boolean')
  46. ];
  47. // Relationships
  48. public function applicantUnit()
  49. {
  50. return $this->belongsTo(\App\Models\Unit::class, 'applicant_unit_id');
  51. }
  52. public function targetUnit()
  53. {
  54. return $this->belongsTo(\App\Models\Unit::class, 'target_unit_id');
  55. }
  56. public function applicantUser()
  57. {
  58. return $this->belongsTo(\App\Models\User::class, 'applicant_user_id');
  59. }
  60. public function responsableUser()
  61. {
  62. return $this->belongsTo(\App\Models\User::class, 'responsable_user_id');
  63. }
  64. // Query Scopes
  65. public function scopeVisibleToUnit($query, int $unitId)
  66. {
  67. return $query->where(function ($q) use ($unitId) {
  68. $q->where('target_unit_id', $unitId)
  69. ->orWhere('applicant_unit_id', $unitId);
  70. });
  71. }
  72. }