LoginSignup
2
2

More than 5 years have passed since last update.

laravel/config 内で objectやcollect を使わないこと!

Posted at

同じようにはまる人のために・・

php artisan config:cache

したら以下のようなエラー

Your configuration files are not serializable.
BadMethodCallException::("Method Illuminate\Support\Collection::__set_state does not exist.")
Error::("Call to undefined method stdClass::__set_state()")

原因

config/hoge.php

return collect([
  (object)[
    'id'=>1,
    'name'=>'hoge'
  ],
  (object)[
    'id'=>2,
    'name'=>'fuga'
  ],
]);

config/*.php で、配列以外を返すとだめみたいです。

解決

config/hoge.php

return [
  [
    'id'=>1,
    'name'=>'hoge'
  ],
  [
    'id'=>2,
    'name'=>'fuga'
  ],
];

受け手側で、collect() するなりする!

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2