Files
zemailnator/app/Providers/AppServiceProvider.php
2025-11-14 02:01:01 -08:00

60 lines
1.6 KiB
PHP

<?php
namespace App\Providers;
use Illuminate\Support\Facades\DB;
use App\Models\Blog;
use App\Models\Menu;
use App\Models\Plan;
use Exception;
use Illuminate\Support\ServiceProvider;
use Laravel\Cashier\Cashier;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
// Only load application data when not in testing environment
if (! $this->app->environment('testing')) {
$this->loadApplicationData();
}
Cashier::calculateTaxes();
}
/**
* Load application data and cache it.
*/
private function loadApplicationData(): void
{
try {
$settings = cache()->remember('app_settings', now()->addHours(6), fn(): array => (array) DB::table('settings')->find(1));
$menus = cache()->remember('app_menus', now()->addHours(6), Menu::all(...));
$blogs = cache()->remember('app_blogs', now()->addHours(6), fn() => Blog::query()->where('is_published', 1)->get());
$plans = cache()->remember('app_plans', now()->addHours(6), Plan::all(...));
config(['app.settings' => (array) $settings]);
config(['app.menus' => $menus]);
config(['app.blogs' => $blogs]);
config(['app.plans' => $plans]);
} catch (Exception) {
// Fail silently if database is not available
// This allows the application to boot during migrations and testing
}
}
}