Open heinbez opened 8 years ago
I'm getting the same error (using Eloquent as a standalone package).
I got the same error when used alone...
I solved it, hopefully this will help anyone that runs across the same error. You need to create a new app container and then bind it to the Facade.
use \Illuminate\Container\Container as Container;
use \Illuminate\Support\Facades\Facade as Facade;
/**
* Setup a new app instance container
*
* @var Illuminate\Container\Container
*/
$app = new Container();
$app->singleton('app', 'Illuminate\Container\Container');
/**
* Set $app as FacadeApplication handler
*/
Facade::setFacadeApplication($app);
in lumen: bootstrap/app.php $app->withFacades();
But I don't konw how to create a new container. Could you help me.Thank you.
@taoongjun Did you try the sample code from @heinbez ? This code is helpful for other Laravel tests, such as enabling the Log facade, in a static class (SUT) test target. Here's is more modern code, tested in a unit test, with Laravel v5.2:
use Illuminate\Foundation\Application; // ideally, near top of file use Illuminate\Support\Facades\Facade; //... $app = new Application(); // Create a facade root, perhaps in setup() $app->singleton('app', Application::class); Facade::setFacadeApplication($app);
hello heinbez, my code show this error, you can help me fix it, tks PHP Fatal error: Uncaught ReflectionException: Class db does not exist in D:\xampp\htdocs\web\wordpress\laravel\vendor\laravel\framework\src\Illuminate\Container\Container.php:729
I have the same problem hoping you can help me to solve
The problem is that the trait forces you to use facades please see the example below :
protected function getDatabaseDriver() {
$key = $this->connection ?: Config::get('database.default');
return Config::get('database.connections.' . $key . '.driver');
}
wouldn't it be better to do something like 👇
protected function getDatabaseDriver() {
$config = app('config');
$key = $this->connection ?: $config->get('database.connections.' . $key . '.driver');
return $config->get('database.connections.' . $key . '.driver');
}
Lumen's users for example might chose not to enable facades at all I don't think it's right to force consumers to use them.
wrong way
public function register()
{
$this->app->bind('Activity', function($app)
{
new Activity;
});
}
right way 👍
public function register()
{
$this->app->bind('Activity', function($app)
{
return new Activity;
});
}
---------------------------------- don't forget return
Thanks for your honesty! But It’s so long time ago, I can’t rember how it’s happening. Thanks again!
在 2019年9月19日,15:21,Hossein Shafiei notifications@github.com 写道:
wrong way
public function register() { $this->app->bind('Activity', function($app) { new Activity; }); } right way 👍
public function register() { $this->app->bind('Activity', function($app) { return new Activity; }); } ---------------------------------- don't forget return
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/nicolaslopezj/searchable/issues/86?email_source=notifications&email_token=AELZFVNTER3GVO2DVWOCRFLQKMR6JA5CNFSM4BULHTDKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7CPRMQ#issuecomment-533002418, or mute the thread https://github.com/notifications/unsubscribe-auth/AELZFVJZRPHYSMUEHFP5XBLQKMR6JANCNFSM4BULHTDA.
I got the same error when used alone..
Hi there,
Great Library! I'm facing an issue issue though, I keep receiving the error "A facade root has not been set" as follow:
Thanks in advance