laravel-app-settings icon indicating copy to clipboard operation
laravel-app-settings copied to clipboard

Your configuration files are not serializable

Open sickleper opened this issue 5 years ago • 6 comments

laravel 6 , php 7.2

sudo php artisan config:cache


LogicException : Your configuration files are not serializable.

at /var/www/html/laravel/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| }

Exception trace:

1 Error::("Call to undefined method Closure::__set_state()") /var/www/html/laravel/bootstrap/cache/config.php:298


Triggered by

// settings group 'setting_group' => function() { return 'user_'.auth()->id();

sickleper avatar Mar 02 '20 15:03 sickleper

Thanks for reporting. what about if you use a class instead of closure for setting group

namespace App;

class SettingGroup {
    public function handle() {
        return 'user_'.auth()->id();
    }
}
'setting_group' => 'App\SettingGroup'

please try, I will update the readme if it works.

saqueib avatar Mar 03 '20 00:03 saqueib

no joy , returns default .. cache key = default, tried Config::set() returns default; probably best setting userid value by cache key? no possible way to run function from config..

sickleper avatar Mar 03 '20 02:03 sickleper

got it fixed for me ..

class SetSettingMiddleware { public function handle($request, Closure $next) { $setting_group = function() { return 'user_'.auth()->id(); } Config::set('app_settings.setting_group', $setting_group); return $next($request);

}

}

// settings group
'setting_group' => '',

sickleper avatar Mar 03 '20 11:03 sickleper

Same issue, and with closure for select. Maybe make an Interface for parametr, eg:

'inputs' => [
  [
      'name' => 'from_email',
      'type' => 'email',
      'label' => 'From Email',
      'placeholder' => 'Application from email',
      'rules' => 'required|email',
  ],
]

to

interface SettingsField(){
  public function getName();
  public function getType();
  ...
}
------------
'inputs' => [
  \App\Settings\EmailField::class,
  \App\Settings\NameField::class,
]

as an option behaivor, for specify fields with logic.

freebuu avatar Dec 18 '20 17:12 freebuu

I have the same issue. Can you help?

mabehiry avatar Feb 15 '21 09:02 mabehiry

This issue still exist by default

below solution is works:

open confi/app_settings.php, find & replace:

'setting_group' => 'App\SettingGroup' or 'setting_group' => '',

sluxzer avatar Jul 01 '21 03:07 sluxzer