From f51de5e7324f766fa903b70c5fe7bd3cc8978f46 Mon Sep 17 00:00:00 2001 From: idevakk <219866223+idevakk@users.noreply.github.com> Date: Mon, 17 Nov 2025 05:35:25 -0800 Subject: [PATCH] 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 --- app/Providers/AppServiceProvider.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 6f9dc23..6164162 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -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]);