Eloquent error: A facade root has not been set

那年仲夏 提交于 2019-11-28 21:07:59
user5972059

You have to change your code to:

$Capsule = new Capsule;
$Capsule->addConnection(config::get('database'));
$Capsule->setAsGlobal();  //this is important
$Capsule->bootEloquent();

And at the beginning of your class file you have to import:

use Illuminate\Database\Capsule\Manager as DB;
Steven

I have just solved this problem by uncommenting $app->withFacades(); in bootstrap/app.php

Why someone marked answer not useful it perfectly worked for me. i was using use Illuminate\Support\Facades\DB as DB; but this worked use Illuminate\Database\Capsule\Manager as DB; after setting capsule as global $capsule->setAsGlobal(); in slim.

Try uncommited app.php $app->withFacades();

If you recently upgrade Laravel on Homestead & VirtualBox environment or do not find any reason that causing please be sure your Vagrant is up to date.

Referance

I had Taylor lock this thread. The past several replies have restated the solution, which is to Upgrade to Virtualbox 6.x, the thread is locked to prevent other issues that are not related from being dogpiled on here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!