3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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() するなりする!

3
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?