Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blade's @inject #33

Open
snopboy opened this issue May 23, 2016 · 0 comments
Open

Blade's @inject #33

snopboy opened this issue May 23, 2016 · 0 comments

Comments

@snopboy
Copy link

snopboy commented May 23, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant