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;
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',

View File

@ -12,5 +12,5 @@ class SiteDataItem extends Model
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 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.");
}
}
}

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_ttl' => env('SITE_DATA_CACHE_TTL', 86400), // seconds
/*
|--------------------------------------------------------------------------