fix: resolve config cache serialization error for optimize command
- Convert Eloquent Collections to arrays before storing in config - Fix Menu::all(), Blog::get(), Plan::all() serialization in AppServiceProvider - Enable php artisan optimize command to cache configuration successfully - Resolve non-serializable value error at "app.menus" key - Ensure compatibility with Laravel config caching mechanism
This commit is contained in:
@@ -51,11 +51,11 @@ class AppServiceProvider extends ServiceProvider
|
||||
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(...));
|
||||
$menus = cache()->remember('app_menus', now()->addHours(6), fn () => Menu::all()->toArray());
|
||||
|
||||
$blogs = cache()->remember('app_blogs', now()->addHours(6), fn () => Blog::query()->where('is_published', 1)->get());
|
||||
$blogs = cache()->remember('app_blogs', now()->addHours(6), fn () => Blog::query()->where('is_published', 1)->get()->toArray());
|
||||
|
||||
$plans = cache()->remember('app_plans', now()->addHours(6), Plan::all(...));
|
||||
$plans = cache()->remember('app_plans', now()->addHours(6), fn () => Plan::all()->toArray());
|
||||
|
||||
$legacySettings = cache()->remember('legacy_app_settings', now()->addHours(6), fn (): array => $this->loadLegacySettings());
|
||||
config(['app.settings' => (array) $legacySettings]);
|
||||
|
||||
Reference in New Issue
Block a user