Your configuration files are not serializable

Viewed 21387

I ran

php artisan config:cache

on my terminal and i got a LogicException

LogicException  : Your configuration files are not serializable.

at C:\xampp\htdocs\{PROJECT}\vendor\laravel\framework\src\Illuminate\Foundation\Console\ConfigCacheCommand.php:68

 64|             require $configPath;
 65|         } catch (Throwable $e) {
 66|             $this->files->delete($configPath);
 67|
 68|             throw new LogicException('Your configuration files are not serializable.', 0, $e);
 69|         }
 70|
 71|         $this->info('Configuration cached successfully!');
 72|     }

 Exception trace:

1   Error::("Call to undefined method Closure::__set_state()")
  C:\xampp\htdocs\{PROJECT}\bootstrap\cache\config.php:241

2   require()
  C:\xampp\htdocs\{PROJECT}\vendor\laravel\framework\src\Illuminate\Foundation\Console\ConfigCacheCommand.php:64

Please use the argument -v to see more details.

I've never encountered this error before when running this command. Please any help will be appreciated. Thank you.

7 Answers

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.

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.

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
];

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(),
    ]);

The solution for me was to remove the 'vendor' folder then:

  1. composer install
  2. composer dump-autoload

Instead of defining as object

'callback' => new App\Http\Controllers\PaymentController()

define as class

'callback' => App\Http\Controllers\PaymentController::class

in any config file

I am facing the same issue when I run

php artisan config:cache

it shows me this error

  Your configuration files are not serializable.
  at vendor\laravel\framework\src\Illuminate\Foundation\Console\ConfigCacheCommand.php:71
  67|             require $configPath;
  68|         } catch (Throwable $e) {
  69|             $this->files->delete($configPath);
  70|
  > 71|             throw new LogicException('Your configuration files are not serializable.', 0, $e);
  72|         }
  73|
  74|         $this->info('Configuration cached successfully!');
  75|     }
  1   bootstrap\cache\config.php:671
  Error::("Call to undefined method Illuminate\Validation\Rules\In::__set_state()")
  2   vendor\laravel\framework\src\Illuminate\Foundation\Console\ConfigCacheCommand.php:67
  require()

When I debug all Configuration in Project/config directory I found a config file config/installer.php created by package https://github.com/rashidlaasri/LaravelInstaller that uses Rule::in(['true', 'false']) so I change this piece of code with 'in:true,false' now work like a charm hope this will help someone

Related