We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Vladimir Stamenković • 8 years ago

Cool article, but not applicable for (at least) Laravel 5.5

Illuminate\Database\Connectors\ConnectionFactory@createConnection
It handles default drivers but also allows for custom one and/or replacements to be inserted:

if ($resolver = Connection::getResolver($driver)) {
return $resolver($connection, $database, $prefix, $config);
}

So, updated version of your DatabaseServiceProvider would be:

public function boot() {

Connection::resolverFor('mysql', function($connection, $database, $prefix, $config) {
return new MySqlConnection($connection, $database, $prefix, $config);
});
}

Also, it's important to register this service provider BEFORE Illuminate\Database\DatabaseServiceProvider::class

Jesse Skrivseth • 5 years ago

This is exactly what I needed. Thank you!

PeterFonda • 10 years ago

Just what I was looking for. Thanks!

Oludare Odunfa G • 11 years ago

a very good start stidges.

Stidges • 11 years ago

Thanks! More content coming later today :)

maxsurguy • 11 years ago

Congrats on your first post :)

Stidges • 11 years ago

Thanks :)

Midix • 10 years ago

Thanks, I hope this will help me to implement a dummy Connection for exporting migration scripts to SQL files, as required by some customer. I tried pretend() function, and it mostly works, but it still requires connection to a database, even when not actually using it, therefore I'll have to somehow override this behavior.

The only problem is that I will have to reconfigure ServiceProvider dynamically, in my custom Artisan command, and I'm not sure yet how to do it.

Dave Amphlett • 10 years ago

Fantastically helpful - thanks for this.

I ended up trying to overload classes Manager and DatabaseManager until I spotted the same bit of code you did - the 'db.connection.{$driver}' bit. At that point googled and eventually found your page which short-cut'ed the rest of the process.

I'm trying to overload the SQLite schema grammar (for in-memory testing) so that it adds default column values if they're not specified - the project I'm working on uses the non-strict mysql syntax :(

imelme • 10 years ago

Is there any idea for singleton redis instance in laravel ?

Thanks anyway ; )

vadimc • 11 years ago

Cool idea with this blog. Hope to see a post on your with Maksim laravel-tricks.com project here, which btw is a great resource of learning already.

Can't wait for more posts anyway.