qcod / laravel-app-settings

Store settings in database with a manager UI for your Laravel app
MIT License
338 stars 53 forks source link

Your configuration files are not serializable #23

Open sickleper opened 4 years ago

sickleper commented 4 years ago

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 'settinggroup' => function() { return 'user'.auth()->id();

saqueib commented 4 years ago

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.

sickleper commented 4 years ago

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 commented 4 years ago

got it fixed for me ..

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

}

}

// settings group
'setting_group' => '',
freebuu commented 3 years ago

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.

mabehiry commented 3 years ago

I have the same issue. Can you help?

sluxzer commented 3 years ago

This issue still exist by default

below solution is works:

open confi/app_settings.php, find & replace:

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