blob: 7328bc4e664e6eba9b1292196116e41a831468aa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
<?php
namespace Engelsystem\Database;
use Engelsystem\Container\ServiceProvider;
use Exception;
use Illuminate\Database\Capsule\Manager as CapsuleManager;
use PDOException;
class DatabaseServiceProvider extends ServiceProvider
{
public function register()
{
$config = $this->app->get('config');
$capsule = $this->app->make(CapsuleManager::class);
$dbConfig = $config->get('database');
$capsule->addConnection(array_merge([
'driver' => 'mysql',
'host' => '',
'database' => '',
'username' => '',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
], $dbConfig));
$capsule->setAsGlobal();
$capsule->bootEloquent();
$capsule->getConnection()->useDefaultSchemaGrammar();
try {
$capsule->getConnection()->getPdo();
} catch (PDOException $e) {
$this->exitOnError();
}
$this->app->instance('db', $capsule);
Db::setDbManager($capsule);
}
/**
* @throws Exception
*/
protected function exitOnError()
{
throw new Exception('Error: Unable to connect to database');
}
}
|