Appointment.php 2.1 KB

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