Your configuration files are not serializable

To find out where exactly the issue is, you can temporarily remove $this->files->delete($configPath); from vendor/laravel/framework/src/Illuminate/Foundation/Console/ConfigCacheCommand.php. By doing so bootstrap/cache/config.php does not get automatically deleted and you can look up the mentioned line (here 241) in the config.php file.


I am facing the same issue. I only add toarray() function to Setting::first() then its worked. config only get array values not array of objects.

config([
        'global' =>  Settings::first()->toarray(),
    ]);

I found a solution to a similar error.

I discovered that my error related to a closure in the /config/sluggable.php file (of a package for managing slugs that I had installed.

My code was as follows:

return [
    reserved => function(Model $model){
        return HelperController::reservedSlugs();
    }
];

I did the following to test if this closure was the cause of the issue:

return [
   reserved => array()
]

Then I ran php artisan optimize. There was no longer an issue - I had found the closure that was causing the problem.

So, instead of the original closure, I did the following to get the same result:

$reservedSlugs = HelperController::reservedSlugs();

return [
    'reserved' => $reservedSlugs
];

Closure serialization is not allowed in Laravel and PHP at large. Look through your configuration files for any file where you used Closures and rewrite that piece of code using traditional functions.