From 17454a77935de978562a6b98ffe471af7682adba Mon Sep 17 00:00:00 2001 From: Matt Young Date: Sat, 13 Dec 2025 12:47:21 -0600 Subject: [PATCH] update welcome page with to use database data --- app/Http/Controllers/WelcomeController.php | 41 ++++++---------------- app/Models/SiteDataItem.php | 2 +- app/Services/SiteDataService.php | 13 ++++--- config/siteData.php | 5 +-- 4 files changed, 24 insertions(+), 37 deletions(-) diff --git a/app/Http/Controllers/WelcomeController.php b/app/Http/Controllers/WelcomeController.php index c455e44..096c00e 100644 --- a/app/Http/Controllers/WelcomeController.php +++ b/app/Http/Controllers/WelcomeController.php @@ -2,40 +2,21 @@ namespace App\Http\Controllers; +use function siteData; + class WelcomeController extends Controller { public function __invoke() { - $concertAuditionDate = 'January 12, 2026'; - $concertAuditionLocation = 'Wagoner High School'; - $concertEntryDeadline = 'December 19, 2025'; - $beginnerEntryDeadline = 'March 13, 2026'; - $concertClinicDates = 'February 2-3, 2026'; - $concertClinicLocation = 'Oologah High School'; - $beginnerClinicDates = 'April 7, 2026'; - $beginnerClinicLocation = 'Wagoner High School'; - $officers = [ - [ - 'office' => 'President', - 'name' => 'Keysto Stotz', - 'school' => 'Skiatook' - ], - [ - 'office' => 'Vice President', - 'name' => 'Jon Matthews', - 'school' => 'Oologah' - ], - [ - 'office' => 'Secretary', - 'name' => 'Kate Aldridge', - 'school' => 'Wagoner' - ], - [ - 'office' => 'Treasurer & Audition Coordinator', - 'name' => 'Matt Young', - 'school' => 'Vinita' - ], - ]; + $concertAuditionDate = siteData('concertAuditionDate'); + $concertAuditionLocation = siteData('concertAuditionLocation'); + $concertEntryDeadline = siteData('concertEntryDeadline'); + $beginnerEntryDeadline = siteData('beginnerEntryDeadline'); + $concertClinicDates = siteData('concertClinicDates'); + $concertClinicLocation = siteData('concertClinicLocation'); + $beginnerClinicDates = siteData('beginnerClinicDates'); + $beginnerClinicLocation = siteData('beginnerClinicLocation'); + $officers = siteData('officers'); return view('welcome', compact( 'officers', diff --git a/app/Models/SiteDataItem.php b/app/Models/SiteDataItem.php index 0ccbcc5..325a5e9 100644 --- a/app/Models/SiteDataItem.php +++ b/app/Models/SiteDataItem.php @@ -12,5 +12,5 @@ class SiteDataItem extends Model protected $keyType = 'string'; - protected $fillable = ['key', 'value']; + protected $fillable = ['key', 'value', 'type']; } diff --git a/app/Services/SiteDataService.php b/app/Services/SiteDataService.php index a1b70f4..ef61b4e 100644 --- a/app/Services/SiteDataService.php +++ b/app/Services/SiteDataService.php @@ -5,14 +5,19 @@ namespace App\Services; use App\Models\SiteDataItem; use InvalidArgumentException; +/** + * @used-by \siteData() + */ class SiteDataService { public function __construct( - protected array $defaults = [], - protected string $cacheKeyPrefix = '', + protected array $defaults, + protected string $cacheKeyPrefix, + protected int $cacheExpiration ) { $this->defaults = config('siteData.defaults', []); $this->cacheKeyPrefix = config('siteData.cache_key_prefix', 'site_data_'); + $this->cacheExpiration = config('siteData.cache_ttl', 86400); } public function get(string $key): mixed @@ -21,7 +26,7 @@ class SiteDataService $cacheKey = $this->cacheKeyPrefix.$key; - return cache()->remember($cacheKey, now()->addDay(), function () use ($key) { + return cache()->remember($cacheKey, $this->cacheExpiration, function () use ($key) { $dataItem = SiteDataItem::find($key); $value = $dataItem?->value ?? $this->defaults[$key]['value']; @@ -67,7 +72,7 @@ class SiteDataService protected function ensureKeyExists(string $key): void { if (! $this->has($key)) { - throw new InvalidArgumentException("Site data key [{$key}] is not defined in configuration."); + throw new InvalidArgumentException("Site data key [$key] is not defined in configuration."); } } } diff --git a/config/siteData.php b/config/siteData.php index 5291b2c..bbdbc61 100644 --- a/config/siteData.php +++ b/config/siteData.php @@ -5,13 +5,14 @@ return [ /* |-------------------------------------------------------------------------- - | Cache Key Prefix + | Cache Data |-------------------------------------------------------------------------- | - | Prefix for data cache keys + | Prefix and TTL for data cache keys | */ 'cache_key_prefix' => 'site_data_', + 'cache_ttl' => env('SITE_DATA_CACHE_TTL', 86400), // seconds /* |--------------------------------------------------------------------------