-
-
Save brain2xml/f5e34449eba935535a2f543ecb91c614 to your computer and use it in GitHub Desktop.
Setup database connection for Eloquent outside of Laravel.
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 DB; | |
use Illuminate\Database\Capsule\Manager as Capsule; | |
class Connection { | |
public function __construct() | |
{ | |
$this->capsule = new Capsule; | |
// Same as database configuration file of Laravel. | |
$this->capsule->addConnection([ | |
'driver' => 'sqlite', | |
'database' => __DIR__.'/database.sqlite', | |
'prefix' => '', | |
], 'default'); | |
$this->capsule->bootEloquent(); | |
$this->capsule->setAsGlobal(); | |
// Hold a reference to established connection just in case. | |
$this->connection = $this->capsule->getConnection('default'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment