Appointment.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Models;
  3. use App\Enums\AppointmentStatusEnum;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. use Illuminate\Database\Eloquent\SoftDeletes;
  7. class Appointment extends Model
  8. {
  9. use SoftDeletes;
  10. protected $guarded = ['id'];
  11. protected function casts(): array
  12. {
  13. return [
  14. 'date' => 'date',
  15. 'requested_at' => 'datetime',
  16. 'status' => AppointmentStatusEnum::class,
  17. 'auto_approved' => 'boolean',
  18. 'service_price' => 'decimal:2',
  19. 'guide_issued_at' => 'datetime',
  20. 'guide_valid_until' => 'date',
  21. ];
  22. }
  23. public function isForDependent(): bool
  24. {
  25. return $this->user_dependent_id !== null;
  26. }
  27. public function user(): BelongsTo
  28. {
  29. return $this->belongsTo(User::class);
  30. }
  31. public function userDependent(): BelongsTo
  32. {
  33. return $this->belongsTo(UserDependent::class)->withTrashed();
  34. }
  35. public function guideIssuedByUser(): BelongsTo
  36. {
  37. return $this->belongsTo(User::class, 'guide_issued_by_user_id');
  38. }
  39. public function approvedByUser(): BelongsTo
  40. {
  41. return $this->belongsTo(User::class, 'approved_by_user_id');
  42. }
  43. public function partnerAgreement(): BelongsTo
  44. {
  45. return $this->belongsTo(PartnerAgreement::class)->withTrashed();
  46. }
  47. public function partnerAgreementService(): BelongsTo
  48. {
  49. return $this->belongsTo(PartnerAgreementService::class)->withTrashed();
  50. }
  51. }