@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use App\Models\Office;
|
||||
use App\Models\SiteSetting;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
/**
|
||||
* Editable company details every public page needs (header, footer, contact
|
||||
* sections). Cached, and cleared whenever offices or settings change.
|
||||
*/
|
||||
class SiteInfo
|
||||
{
|
||||
public const CONTACT_KEY = 'contact';
|
||||
|
||||
private const CACHE_KEY = 'site-info';
|
||||
|
||||
/**
|
||||
* Contact details used until an admin saves their own.
|
||||
*
|
||||
* @var array{phone: string, whatsapp: string, email_busdev: string, email_support: string}
|
||||
*/
|
||||
public const DEFAULT_CONTACT = [
|
||||
'phone' => '(021) 7266-3353',
|
||||
'whatsapp' => '0818-0218-9425',
|
||||
'email_busdev' => 'busdev@probindo.com',
|
||||
'email_support' => 'support@probindo.com',
|
||||
];
|
||||
|
||||
/**
|
||||
* @return array{contact: array<string, string>, offices: list<array<string, mixed>>}
|
||||
*/
|
||||
public static function get(): array
|
||||
{
|
||||
return Cache::rememberForever(self::CACHE_KEY, fn () => [
|
||||
'contact' => [...self::DEFAULT_CONTACT, ...SiteSetting::get(self::CONTACT_KEY)],
|
||||
'offices' => Office::query()
|
||||
->orderBy('sort_order')
|
||||
->orderBy('id')
|
||||
->get(['id', 'name', 'icon', 'building', 'street', 'area', 'city', 'district', 'phone', 'maps_url', 'sort_order'])
|
||||
->toArray(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function forget(): void
|
||||
{
|
||||
Cache::forget(self::CACHE_KEY);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user