Skip to content

Commit

Permalink
Display menu with same date logic everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
carsso committed Dec 6, 2024
1 parent db6b0c7 commit faaf05e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
12 changes: 7 additions & 5 deletions app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ public function index()
}
public function menu($dateString = null)
{
if(!$dateString) {
$dateString = date('Y-m-d');
$dateToday = strtotime('today 10 am');
$date = $dateToday;
if(date('H') >= 15) {
$date = strtotime('+1 day', $date);
}
$date = strtotime('today 10 am');
if(preg_match('/^\d{4}-\d{2}-\d{2}$/', $dateString)) {
$date = strtotime($dateString.' 10 am');
}
if(date('N', $date) >= 6) {
$date = strtotime('+1 week', $date);
$menu = Menu::where('date', '>=', date('Y-m-d', $date))->orderBy('date', 'asc')->first();
if($menu) {
$date = strtotime($menu->date.' 10 am');
}
$mondayTime = strtotime('monday this week 10 am', $date);
$sundayTime = strtotime('sunday this week 10 am', $date);
Expand Down
11 changes: 5 additions & 6 deletions app/Http/Controllers/MenuController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,17 @@ class MenuController extends Controller
{
public function menu($dateString = null)
{
if(!$dateString) {
$dateString = date('Y-m-d');
}
$date = strtotime('today 10 am');
$dateToday = strtotime('today 10 am');
$date = $dateToday;
if(date('H') >= 15) {
$date = strtotime('+1 day', $date);
}
if(preg_match('/^\d{4}-\d{2}-\d{2}$/', $dateString)) {
$date = strtotime($dateString.' 10 am');
}
if(date('N', $date) >= 6) {
$date = strtotime('+1 week', $date);
$menu = Menu::where('date', '>=', date('Y-m-d', $date))->orderBy('date', 'asc')->first();
if($menu) {
$date = strtotime($menu->date.' 10 am');
}
$mondayTime = strtotime('monday this week 10 am', $date);
$sundayTime = strtotime('sunday this week 10 am', $date);
Expand Down

0 comments on commit faaf05e

Please sign in to comment.