Created
November 8, 2024 21:24
-
-
Save nuernbergerA/07e167b7e71025c8fd45c8db0d86f470 to your computer and use it in GitHub Desktop.
4-a-a-ron
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use Illuminate\Database\Connection; | |
use Illuminate\Database\Connectors\ConnectionFactory; | |
use Illuminate\Support\ServiceProvider; | |
use App\Database\CustomConnection; | |
class CustomDatabaseServiceProvider extends ServiceProvider | |
{ | |
public function register() | |
{ | |
// Extend the ConnectionFactory with a custom resolver | |
$this->app->resolving('db.factory', function (ConnectionFactory $factory) { | |
$factory->extend('libsql', function ($config, $name) { | |
// Create a PDO instance | |
$pdo = new \PDO($config['dsn'], $config['username'], $config['password'], $config['options'] ?? []); | |
// Return an instance of your CustomConnection | |
return new SqLiteConnection($pdo, $name, $config); | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment