I am working on the laravel project, which I have to show the availability of each doctor for all the week, so I just add the name of the day and the availability ( start time, end time ), but I couldn't match the date with every day with the day.
This is the controller :
public function rdv( $ID)
{
$calendar = collect([]);
$model=doc::findOrFail($ID);
//Monday
$mondayMorningStart = strtotime ($model->Lun_mat_de[0]) ; //Get Timestamp
$mondayMorningEnd = strtotime($model->Lun_mat_de[1]);
$mondayMidiStart = strtotime($model->Lun_apres_a[0]);
$mondayMidiEnd = strtotime($model->Lun_apres_a[1]); //Get Timestamp
$calendar->monday = getAvailabilityCalendar($mondayMorningStart, $mondayMorningEnd, $mondayMidiStart, $mondayMidiEnd);
//Tuesday
..
return view ('/rendezvous',['go'=> $model],['calendar'=>$calendar] );
function getAvailabilityCalendar($morningStart, $morningEnd, $eveningStart, $eveningEnd)
{
$calendar = collect([]);
/**
* Morning
*/
$start = $morningStart;
$end = $morningEnd;
while($start < $end ) {
$calendar->push($start);
$start = strtotime('+1 hour', $start);
}
/**
* Evenning
*/
$start = $eveningStart;
$end = $eveningEnd;
while($start < $end ) {
$calendar->push($start);
$start = strtotime('+1 hour', $start);
}
$calendar->transform(function($item) {
return date('G:i', $item);
});
return $calendar;
}
This is the view for the calendar:
<button class="btn btn-sm btn-info" id="prev"> < </button>
<div id="date" style="height:100px; width:300px; font-size:17px">
</div>
<button class="btn btn-sm btn-info" id="next"> > </button>
</div>
<h2>Lun</h2>
@foreach($calendar->monday as $ja)
<button class="btn btn-sm btn-info"> {{$ja}} </button> </br>
@endforeach
</div>
<div class="col">
<h2>Mar</h2>
@foreach($calendar->tuesday as $ja)
<button class="btn btn-sm btn-info"> {{$ja}} </button> </br>
@endforeach
</div>
<div class="col">
<h2>Mer</h2>
@foreach($calendar->wednesday as $ja)
<button class="btn btn-sm btn-info"> {{$ja}} </button> </br>
@endforeach
</div>
<div class="col">
<h2>Jeu</h2>
@foreach($calendar->thursday as $ja)
<button class="btn btn-sm btn-info"> {{$ja}} </button> </br>
@endforeach
</div>
