|SupportTicket newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|SupportTicket newQuery() * @method static \Illuminate\Database\Eloquent\Builder|SupportTicket query() * @method static \Illuminate\Database\Eloquent\Builder|SupportTicket whereApplicantUserId($value) * @method static \Illuminate\Database\Eloquent\Builder|SupportTicket whereCreatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|SupportTicket whereDeletedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|SupportTicket whereDescription($value) * @method static \Illuminate\Database\Eloquent\Builder|SupportTicket whereId($value) * @method static \Illuminate\Database\Eloquent\Builder|SupportTicket whereResponsableUserId($value) * @method static \Illuminate\Database\Eloquent\Builder|SupportTicket whereSeverity($value) * @method static \Illuminate\Database\Eloquent\Builder|SupportTicket whereStudentId($value) * @method static \Illuminate\Database\Eloquent\Builder|SupportTicket whereSupportStatusId($value) * @method static \Illuminate\Database\Eloquent\Builder|SupportTicket whereTitle($value) * @method static \Illuminate\Database\Eloquent\Builder|SupportTicket whereUnitId($value) * @method static \Illuminate\Database\Eloquent\Builder|SupportTicket whereUpdatedAt($value) * @mixin \Eloquent */ class SupportTicket extends Model { use HasFactory; protected $table = 'support_tickets'; protected $guarded = [ 'id', // Add more fields that shouldn't be edited here ]; protected $casts = [ 'created_at' => 'datetime', 'updated_at' => 'datetime', // Add your casts here (e.g., 'is_active' => 'boolean') ]; // Relationships public function applicantUnit() { return $this->belongsTo(\App\Models\Unit::class, 'applicant_unit_id'); } public function targetUnit() { return $this->belongsTo(\App\Models\Unit::class, 'target_unit_id'); } public function applicantUser() { return $this->belongsTo(\App\Models\User::class, 'applicant_user_id'); } public function responsableUser() { return $this->belongsTo(\App\Models\User::class, 'responsable_user_id'); } // Query Scopes public function scopeVisibleToUnit($query, int $unitId) { return $query->where(function ($q) use ($unitId) { $q->where('target_unit_id', $unitId) ->orWhere('applicant_unit_id', $unitId); }); } }