3

So Tapestry has its default DatabaseServiceProvider.php with the below code inside.

$this->app->singleton('db.factory', function ($app) {
    return new ConnectionFactory($app);
});

I want to be able to use the db.factory facade created by this to make a new connection. But when I call

db.factory::make($config,$factory);

Of course this doesn't work, I get an error:

Use of undefined constant db - assumed 'db'

How can I do this?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Shardj
  • 1,800
  • 2
  • 17
  • 43

1 Answers1

2

That singleton has to be accessed directly through the service container. My favorite way to do that is the app() helper function:

app('db.factory')->make($config, $factory);
lukasgeiter
  • 147,337
  • 26
  • 332
  • 270
  • Thanks Lukas, are you able to explain to me why. Trying to learn Laravel is pretty overwhelming for me – Shardj Jul 02 '15 at 12:50
  • 2
    *why* is a pretty broad question... `db.factory::` would work if this was a facade. Facades basically do nothing else than resolve a certain class from the container (like we do with `app('db.factory')`) and "transform" a static method call into a dynamic one. That's not possible with `db.factory` because it doesn't have a facade. Let me know if something is unclear :) – lukasgeiter Jul 02 '15 at 12:56
  • No that's perfect thanks, now I'm off to try and find out why one of my middlewares has stopped working – Shardj Jul 02 '15 at 13:11