0

This is a two-part question but I believe they are closely related.

I am learning calling classes with Laravel, and trying to clarify when a "bound" (if I am saying this correctly) class may be called. This is Laravel 4.2.)

Well into the application, in file app/lib/Repositories/Node/EloquentNodeRepository.php, I am able to call this:

Db::enableQueryLog();

and it works great.

However, trying that same command in app/client/controllers/PageController.php (the parent method, specified in routes.php), it cannot find Db but instead I use this (and it works):

\Illuminate\Support\Facades\Db::enableQueryLog();

That is not the primary issue, though the obvious question is why I cannot just use Db yet, or should I even expect this.

My question, however, is: "When is the earliest point in my application where I may use MyClass::doSomething() as with Db? I see that index.php calls application/start.php which eventually initialised $app - but I do not know when Facades have been activated or classes like Connection have been bound to the Facade. And I could use help on this. Thanks.

jedrzej.kurylo
  • 39,591
  • 9
  • 98
  • 107
Oliver Williams
  • 5,966
  • 7
  • 36
  • 78
  • You can call your Classes or any Classes right away (if they exist in code) to call them they need to be imported at the top of your controller ...and for default laravel classes/facades you don't need to import them you can call them with backslash. For example `\DB::enableQueryLog();` – lewis4u Apr 25 '17 at 11:18
  • @lewis4u, I'm looking for a specific location because that doesn't work. In index.php you have `$app = require_once __DIR__.'/bootstrap/start.php';` - well, calling `\Db::enableQueryLog()` doesn't work there (class not found). Only works after `$app->run()`. But **where** in the stack can it first be called? – Oliver Williams Apr 25 '17 at 11:32
  • Well you will have to go through the documentation....i am not sure in which layer is that exactly triggered.... – lewis4u Apr 25 '17 at 11:38
  • Alright.. I have actually been looking under Facade and Service container, trying to understand that. Maybe I'll try Stack Overflow ;) – Oliver Williams Apr 25 '17 at 11:43

0 Answers0