From 0a50c93d3a5a5b3d79fbcf0c0891906b99fb6a38 Mon Sep 17 00:00:00 2001 From: floppydiskette Date: Fri, 27 Dec 2024 20:28:16 +0000 Subject: [PATCH] Server-side "is it christmas" --- app/View/Components/Layout.php | 26 ++++++++++++++------- resources/views/components/layout.blade.php | 4 +++- resources/views/home.blade.php | 17 +------------- 3 files changed, 21 insertions(+), 26 deletions(-) diff --git a/app/View/Components/Layout.php b/app/View/Components/Layout.php index 576d1a0..c8ba3e0 100644 --- a/app/View/Components/Layout.php +++ b/app/View/Components/Layout.php @@ -3,24 +3,32 @@ namespace App\View\Components; use Closure; +use DateTime; use Illuminate\Contracts\View\View; use Illuminate\View\Component; -class Layout extends Component -{ +class Layout extends Component { /** * Create a new component instance. */ - public function __construct() - { - // - } + public function __construct() {} /** * Get the view / contents that represent the component. */ - public function render(): View|Closure|string - { - return view('components.layout'); + public function render(): View|Closure|string { + return view('components.layout', [ + 'isChristmas' => $this->isItChristmas() + ]); + } + + public function isItChristmas() : bool { + $currentDate = new DateTime(); + $currentYear = intval($currentDate->format('Y')); + + $startDate = new DateTime("$currentYear-11-10"); + $endDate = new DateTime(($currentYear + 1) . "-01-01"); + + return $currentDate >= $startDate && $currentDate < $endDate; } } diff --git a/resources/views/components/layout.blade.php b/resources/views/components/layout.blade.php index 4538be4..e7ced26 100644 --- a/resources/views/components/layout.blade.php +++ b/resources/views/components/layout.blade.php @@ -10,7 +10,8 @@ - {!! (intval(date('n')) == 12) ? '' : '' !!} + @if ($isChristmas)@endif + @@ -36,6 +37,7 @@