Support the ongoing development of Laravel.io →
Database IOC Architecture
Last updated 3 months ago.
0

According to the docs this seems like it should work?

https://laravel.com/docs/5.4/providers . (see Boot Method Dependency Injection)

0

You don't need a service provider instance .. you need the class that was created by service provider .. your code should look like

public function boot(\Illuminate\Support\Facades\DB $db)
{
    // do stuff with $db
    return "test";
}

because the database service provider register a db singleton

$this->app->singleton('db', function ($app) {
            return new DatabaseManager($app, $app['db.factory']);
        });

also you could use

$db = $app->make('db')

instead of injecting

0

Sign in to participate in this thread!

Full Stack Europe

Your banner here too?

nkiermaier nkiermaier nkiermaier Joined 11 Sep 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 Laravel.io - All rights reserved.