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

后端 未结 3 1290
再見小時候
再見小時候 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:41

    While running TestCase in Laravel 6.x and above, I often encounter this error. I realized that the unit test is extended from PHPUnit TestClass rather than Laravel TestCase. So change PHPUnit\Framework\TestCase; to Tests\TestCase.

    <?php
    
    
    use Tests\TestCase;
    
    class ArtifactTest extends TestCase{
    
    }
    
    
    0 讨论(0)
  • 2021-02-02 01:48

    go to bootstrap/app.php

    Just uncomment

    $app->withEloquent();
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题