| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace App\Models;
- use App\Enums\AppointmentStatusEnum;
- use App\Enums\AppointmentTypeEnum;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- use Illuminate\Database\Eloquent\SoftDeletes;
- class Appointment extends Model
- {
- use SoftDeletes;
- protected $guarded = ['id'];
- protected function casts(): array
- {
- return [
- 'date' => 'date',
- 'requested_at' => 'datetime',
- 'accepted_at' => 'datetime',
- 'refused_at' => 'datetime',
- 'status' => AppointmentStatusEnum::class,
- 'type' => AppointmentTypeEnum::class,
- 'auto_approved' => 'boolean',
- 'service_price' => 'decimal:2',
- 'guide_issued_at' => 'datetime',
- 'guide_valid_until' => 'date',
- ];
- }
- public function isForDependent(): bool
- {
- return $this->user_dependent_id !== null;
- }
- public function isExame(): bool
- {
- return $this->type === AppointmentTypeEnum::EXAME;
- }
- public function user(): BelongsTo
- {
- return $this->belongsTo(User::class);
- }
- public function userDependent(): BelongsTo
- {
- return $this->belongsTo(UserDependent::class)->withTrashed();
- }
- public function guideIssuedByUser(): BelongsTo
- {
- return $this->belongsTo(User::class, 'guide_issued_by_user_id');
- }
- public function approvedByUser(): BelongsTo
- {
- return $this->belongsTo(User::class, 'approved_by_user_id');
- }
- public function refusedByUser(): BelongsTo
- {
- return $this->belongsTo(User::class, 'refused_by_user_id');
- }
- public function exams(): HasMany
- {
- return $this->hasMany(AppointmentExam::class);
- }
- public function partnerAgreement(): BelongsTo
- {
- return $this->belongsTo(PartnerAgreement::class)->withTrashed();
- }
- public function partnerAgreementService(): BelongsTo
- {
- return $this->belongsTo(PartnerAgreementService::class)->withTrashed();
- }
- }
|