$proposals * @property-read int|null $proposals_count * @property-read \App\Models\Provider|null $provider * @property-read \Illuminate\Database\Eloquent\Collection $refuses * @property-read int|null $refuses_count * @property-read \Illuminate\Database\Eloquent\Collection $reviews * @property-read int|null $reviews_count * @method static \Illuminate\Database\Eloquent\Builder|Schedule newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Schedule newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Schedule onlyTrashed() * @method static \Illuminate\Database\Eloquent\Builder|Schedule query() * @method static \Illuminate\Database\Eloquent\Builder|Schedule whereAddressId($value) * @method static \Illuminate\Database\Eloquent\Builder|Schedule whereCancelText($value) * @method static \Illuminate\Database\Eloquent\Builder|Schedule whereCancelledBy($value) * @method static \Illuminate\Database\Eloquent\Builder|Schedule whereClientId($value) * @method static \Illuminate\Database\Eloquent\Builder|Schedule whereCode($value) * @method static \Illuminate\Database\Eloquent\Builder|Schedule whereCodeVerified($value) * @method static \Illuminate\Database\Eloquent\Builder|Schedule whereCreatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|Schedule whereDate($value) * @method static \Illuminate\Database\Eloquent\Builder|Schedule whereDeletedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|Schedule whereEndTime($value) * @method static \Illuminate\Database\Eloquent\Builder|Schedule whereId($value) * @method static \Illuminate\Database\Eloquent\Builder|Schedule whereOffersMeal($value) * @method static \Illuminate\Database\Eloquent\Builder|Schedule wherePeriodType($value) * @method static \Illuminate\Database\Eloquent\Builder|Schedule whereProviderId($value) * @method static \Illuminate\Database\Eloquent\Builder|Schedule whereScheduleType($value) * @method static \Illuminate\Database\Eloquent\Builder|Schedule whereStartTime($value) * @method static \Illuminate\Database\Eloquent\Builder|Schedule whereStatus($value) * @method static \Illuminate\Database\Eloquent\Builder|Schedule whereTotalAmount($value) * @method static \Illuminate\Database\Eloquent\Builder|Schedule whereUpdatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|Schedule withTrashed(bool $withTrashed = true) * @method static \Illuminate\Database\Eloquent\Builder|Schedule withoutTrashed() * @mixin \Eloquent */ class Schedule extends Model { use HasFactory, SoftDeletes; protected $fillable = [ 'client_id', 'provider_id', 'address_id', 'date', 'period_type', 'schedule_type', 'start_time', 'end_time', 'status', 'total_amount', 'code', 'code_verified', 'offers_meal', 'cancel_text', 'cancelled_by', ]; protected $casts = [ 'date' => 'date', 'code_verified' => 'boolean', 'total_amount' => 'decimal:2', 'offers_meal' => 'boolean', ]; public function client() { return $this->belongsTo(Client::class)->select( 'id', 'user_id', 'document', 'average_rating', 'external_customer_id', 'external_customer_code', ); } public function provider() { return $this->belongsTo(Provider::class); } public function address() { return $this->belongsTo(Address::class, 'address_id')->select('id', 'district'); } public function customSchedule() { return $this->hasOne(CustomSchedule::class)->select('id', 'service_type_id', 'min_price', 'max_price', 'schedule_id'); } public function proposals() { return $this->hasMany(ScheduleProposal::class); } public function refuses() { return $this->hasMany(ScheduleRefuse::class); } public function reviews() { return $this->hasMany(Review::class); } // public function ensureCustomerPhone(?string $fallbackPhone = null): void { $phone = $this->client?->user?->phone ?? $fallbackPhone; $digits = preg_replace('/\D+/', '', (string) $phone) ?? ''; if (strlen($digits) >= 10) { return; } throw new \InvalidArgumentException( 'Voce precisa cadastrar um numero de celular valido no seu perfil para concluir o pagamento.' ); } }