Skip to content

Instantly share code, notes, and snippets.

@pekhee
Created April 5, 2014 23:56
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save pekhee/9999638 to your computer and use it in GitHub Desktop.
Save pekhee/9999638 to your computer and use it in GitHub Desktop.
Setup database connection for Eloquent outside of Laravel.
<?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