DatabaseServiceProvider.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace app\framework\Database;
  3. use app\framework\Database\Connectors\ConnectionFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. class DatabaseServiceProvider extends \Illuminate\Database\DatabaseServiceProvider
  6. {
  7. /**
  8. * Register the service provider.
  9. *
  10. * @return void
  11. */
  12. public function register()
  13. {
  14. Model::clearBootedModels();
  15. $this->registerEloquentFactory();
  16. $this->registerQueueableEntityResolver();
  17. // The connection factory is used to create the actual connection instances on
  18. // the database. We will inject the factory into the manager so that it may
  19. // make the connections while they are actually needed and not of before.
  20. $this->app->singleton('db.factory', function ($app) {
  21. return new ConnectionFactory($app);
  22. });
  23. // The database manager is used to resolve various connections, since multiple
  24. // connections might be managed. It also implements the connection resolver
  25. // interface which may be used by other components requiring connections.
  26. $this->app->singleton('db', function ($app) {
  27. return new DatabaseManager($app, $app['db.factory']);
  28. });
  29. $this->app->bind('db.connection', function ($app) {
  30. return $app['db']->connection();
  31. });
  32. }
  33. }