There is a good package for working with 'time slot' (period')
Only show dates which have available time slots
I have two separate tables with dates and time slots. User can only book a date with a time slot in a week from now. I want to make it more clear for a user and let him see which dates have available time slots(and if none is then show a message that appointments are closed, please wait for another week). So I need to get an array of available dates. What are the best options to do something like that, is it possible to use eloquent in this case for example? My appointments model:
protected $fillable = [
'first_name',
'last_name',
'email',
'phone_number',
'date',
'time_slot_id',
'comment'
];
protected $dates = [
'date'
];
public function time_slot(){
return $this->belongsTo(TimeSlot::class);
}
Time slot model:
protected $fillable = ['time', 'status'];
protected $casts = [
'status' => TimeSlotStatus::class,
];
public function appointments(){
return $this->hasMany(Appointment::class);
}
Function in the controller, here I already have a week array with a all of the dates of the next week, so what is the best way to proceed from here?
$min_date = Carbon::today();
$week = [];
for ($i=0; $i <7 ; $i++) {
$week[] = $min_date->now()->addDay($i)->format('Y-m-d');//push the current day and plus the mount of $i
}
Please or to participate in this conversation.