I have a table, OperatingHours where 7 rows of data are recorded for the day of the week (Monday, Tuesday, Wednesday until Sunday). And there's a data column where user's can set true/false whether the clinic is open for the week.
I want to generate a list of date from current date till the end of the year, by the day of the week where the clinic is open. Currently below are my controller codes for the methods and I am getting the following error:
DateTime::modify(): Failed to parse time string (this [{"day":"Monday"},{"day":"Tuesday"},{"day":"Wednesday"},{"day":"Thursday"},{"day":"Friday"}]) at position 0 (t): The timezone could not be found in the database
public function index(){
$operatingDays = OperatingHour::where('clinic_open', true)->get('day');
$currentDate = Carbon::now()->toDateTimeString();
$endOfYear - Carbon::now()->endOfYear()->toDateTimeString();
$dt = $this->getWorkDayInRange($operatingDays, $currentDate, $endOfYear);
$data = [
'dt' = $dt,
];
return view('appointment', $data);
}
public function getWorkDayInRange($workday, $fromDate, $toDate){
$dates = [];
$startDate = Carbon::parse($fromDate)->modify("this $workday");
$endDate = Carbon::parse($toDate);
//lte = less than or equal
for ($date = $startDate; $date->lte($endDate); $date->addWeek()) {
$dates[] = $date->toDateString();
}
return $dates;
}
getWorkDayInRange($operatingDays,...
pass an arraygetWorkDayInRange($workday
expect a workday stringFailed to parse time string
error message show you what you passed and so clearly there is now way to get any proper date from an array JSON. – KyleK