Call to a member function connection() on a non-object error on Laravel 5

后端 未结 3 1292
再見小時候
再見小時候 2021-02-02 01:05

I want to store user configuration data on database and I\'m following this forum thread about it http://forumsarchive.laravel.io/viewtopic.php?id=10406 but when I implemented i

3条回答
  •  梦如初夏
    2021-02-02 01:58

    Working with models in your settings files is not the best way to use them.

    Your problem is, that your model query started BEFORE Laravel started it's services. That's why, when you try to make your query, model can't resolve it's connection, because DB service hasn't been initiated.

    If you want do this stuff, create your own ServiceProvider and update your config there, or do it right in the boot method of your existing AppServiceProvider.

提交回复
热议问题