Laravel-Blade
Laravel-Blade copied to clipboard
Blade's @inject
trafficstars
It doesn't work because the global function app() doesn't exist, put this somewhere before the Blade class is instantiated to make it work.
use Illuminate\Container\Container;
$container = new Container();
Container::setInstance($container);
$container = Container::getInstance();
if (! function_exists('app')) {
/**
* Get the available container instance.
*
* @param string $make
* @param array $parameters
* @return mixed|\Illuminate\Foundation\Application
*/
function app($make = null, $parameters = [])
{
if (is_null($make)) {
return Container::getInstance();
}
return Container::getInstance()->make($make, $parameters);
}
}
Now injecting into the views works (it's basically instantiating a class of your choice using the Container) and you can also use this DI container for your app.