33 lines
2.1 KiB
PHP
33 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\AppointmentStatus;
|
|
use App\Models\Concerns\UsesStringIds;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class Appointment extends Model
|
|
{
|
|
use UsesStringIds;
|
|
|
|
public const CREATED_AT = 'createdAt';
|
|
public const UPDATED_AT = 'updatedAt';
|
|
protected $table = 'Appointment';
|
|
protected $fillable = ['businessId', 'customerId', 'staffId', 'status', 'startAt', 'endAt', 'notes', 'discountAmount', 'cancellationReason', 'cancelledAt', 'cancelledByUserId', 'createdByUserId'];
|
|
protected function casts(): array { return ['status' => AppointmentStatus::class, 'startAt' => 'datetime', 'endAt' => 'datetime', 'cancelledAt' => 'datetime', 'discountAmount' => 'decimal:2']; }
|
|
public function business(): BelongsTo { return $this->belongsTo(Business::class, 'businessId'); }
|
|
public function customer(): BelongsTo { return $this->belongsTo(CustomerProfile::class, 'customerId'); }
|
|
public function staff(): BelongsTo { return $this->belongsTo(StaffProfile::class, 'staffId'); }
|
|
public function services(): HasMany { return $this->hasMany(AppointmentService::class, 'appointmentId'); }
|
|
public function guestAccessToken(): HasOne { return $this->hasOne(GuestAppointmentAccessToken::class, 'appointmentId'); }
|
|
public function calendarEvents(): HasMany { return $this->hasMany(AppointmentCalendarEvent::class, 'appointmentId'); }
|
|
public function loyaltyTransactions(): HasMany { return $this->hasMany(LoyaltyTransaction::class, 'appointmentId'); }
|
|
public function notifications(): HasMany { return $this->hasMany(Notification::class, 'appointmentId'); }
|
|
public function appliedLoyaltyRewards(): HasMany { return $this->hasMany(LoyaltyReward::class, 'appliedToAppointmentId'); }
|
|
public function cancelledByUser(): BelongsTo { return $this->belongsTo(User::class, 'cancelledByUserId'); }
|
|
public function createdByUser(): BelongsTo { return $this->belongsTo(User::class, 'createdByUserId'); }
|
|
}
|