update welcome page with to use database data

This commit is contained in:
Matt Young 2025-12-13 12:47:21 -06:00
parent ac22e7ec3d
commit 17454a7793
4 changed files with 24 additions and 37 deletions

View File

@ -2,40 +2,21 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use function siteData;
class WelcomeController extends Controller class WelcomeController extends Controller
{ {
public function __invoke() public function __invoke()
{ {
$concertAuditionDate = 'January 12, 2026'; $concertAuditionDate = siteData('concertAuditionDate');
$concertAuditionLocation = 'Wagoner High School'; $concertAuditionLocation = siteData('concertAuditionLocation');
$concertEntryDeadline = 'December 19, 2025'; $concertEntryDeadline = siteData('concertEntryDeadline');
$beginnerEntryDeadline = 'March 13, 2026'; $beginnerEntryDeadline = siteData('beginnerEntryDeadline');
$concertClinicDates = 'February 2-3, 2026'; $concertClinicDates = siteData('concertClinicDates');
$concertClinicLocation = 'Oologah High School'; $concertClinicLocation = siteData('concertClinicLocation');
$beginnerClinicDates = 'April 7, 2026'; $beginnerClinicDates = siteData('beginnerClinicDates');
$beginnerClinicLocation = 'Wagoner High School'; $beginnerClinicLocation = siteData('beginnerClinicLocation');
$officers = [ $officers = siteData('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'
],
];
return view('welcome', compact( return view('welcome', compact(
'officers', 'officers',

View File

@ -12,5 +12,5 @@ class SiteDataItem extends Model
protected $keyType = 'string'; protected $keyType = 'string';
protected $fillable = ['key', 'value']; protected $fillable = ['key', 'value', 'type'];
} }

View File

@ -5,14 +5,19 @@ namespace App\Services;
use App\Models\SiteDataItem; use App\Models\SiteDataItem;
use InvalidArgumentException; use InvalidArgumentException;
/**
* @used-by \siteData()
*/
class SiteDataService class SiteDataService
{ {
public function __construct( public function __construct(
protected array $defaults = [], protected array $defaults,
protected string $cacheKeyPrefix = '', protected string $cacheKeyPrefix,
protected int $cacheExpiration
) { ) {
$this->defaults = config('siteData.defaults', []); $this->defaults = config('siteData.defaults', []);
$this->cacheKeyPrefix = config('siteData.cache_key_prefix', 'site_data_'); $this->cacheKeyPrefix = config('siteData.cache_key_prefix', 'site_data_');
$this->cacheExpiration = config('siteData.cache_ttl', 86400);
} }
public function get(string $key): mixed public function get(string $key): mixed
@ -21,7 +26,7 @@ class SiteDataService
$cacheKey = $this->cacheKeyPrefix.$key; $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); $dataItem = SiteDataItem::find($key);
$value = $dataItem?->value ?? $this->defaults[$key]['value']; $value = $dataItem?->value ?? $this->defaults[$key]['value'];
@ -67,7 +72,7 @@ class SiteDataService
protected function ensureKeyExists(string $key): void protected function ensureKeyExists(string $key): void
{ {
if (! $this->has($key)) { 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.");
} }
} }
} }

View File

@ -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_key_prefix' => 'site_data_',
'cache_ttl' => env('SITE_DATA_CACHE_TTL', 86400), // seconds
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------