im currently making this queue web, so i want to select the longest overall queue time. im able to select the longest queue time per category but somehow when i want to retrieve the longest overall queue time, my model doesnt select the correct data.
Controller to select the queue time
This part to take overall longest queue time
$longestQ = queueModel::max('wait_time');
this part to take the longest queue time per category
$longestQ1 = queueModel::where('category',$categories[0]->QName)->whereDate('created_at','=',now())->max('wait_time');
this is the result of the overall queue time
"7:27" // appHttpControllersSpvController.php:606
and this is the result of the longest queue time of 1 category, it should be the longest overall
"36:59" // appHttpControllersSpvController.php:929
could anybody explain this the way a dummy could undderstand pls.
if you need more part of the code, i would be happy to provide. thanks in advance
i have tried to convert the column content from string to time but still doesnt work,
also i’ve tried using some query builder but still giving the same result as the eloquent
2
Answers
It will return the maximum value for
wait_time
across all rows in the table, rather than just the rows for the current day. To select the longest overall queue time for the current day, update your query to filter by the current day using thewhereDate
:If
wait_time
is stored as a string, you may need to convert it to a numeric format using attribute casting.If your wait_time column is of type VarChar (i.e. string), then the database will compare its values as strings. It has no idea of the meaning of those strings, it just looks at them character by character.
Given the following list:
The maximum value, i.e. the one that comes last in alphabetical order, is "7:27", because any string starting "7" will come after any string starting "0", "3", or "5".
To avoid this, you need to do one of two things: