Laravel IoC outside of Laravel
I am using this repo as a basis for a new PHP CLI project using Eloquent as ORM.
When creating a new Eloquent capsule
, you have an option setAsGlobal
that makes the DB capsule accessible from anywhere in your code.
Does this mean that Laravel Container is being used? Or does it just affect the DB object?
I used pimple as my container, but if Laravel already has a container that I can communicate with via Eloquent, this is much easier. I want to link the journalist, Eloquent capsule and possibly the settings object to the global container so that I can access it from anywhere.
source to share
No, it doesn't use the Laravels container. If you look at the method in the tag: ( github.com )
public function setAsGlobal()
{
static::$instance = $this;
}
You can see that it just sets a static property of the class containing the current instance, so it will be reused for subsequent calls.
source to share
Try this solution. Hope it helps.
https://gist.github.com/reinink/9112262
"require":
{
"illuminate/container": "4.0.*@dev",
}
source to share