Skip to content

Instantly share code, notes, and snippets.

@nuernbergerA
Created November 8, 2024 21:24
Show Gist options
  • Save nuernbergerA/07e167b7e71025c8fd45c8db0d86f470 to your computer and use it in GitHub Desktop.
Save nuernbergerA/07e167b7e71025c8fd45c8db0d86f470 to your computer and use it in GitHub Desktop.
4-a-a-ron
<?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