2

In this stackoverflow post,

Get the query executed in Laravel 3/4

Ricardo Rossi provided a great answer about using Kint and a custom class to easily output information about a Laravel query created using the query builder.

I was able to setup Kent using composer but am new to Laravel and haven't used PHP since version 4.

Could someone please provide an example describing how to create a class which can then be called from anywhere. In his example, Ricardo says he uses "DBH::q()".

At the moment, I'm stuck requiring common files just like in good old PHP4 days.

Thanks

Community
  • 1
  • 1
user2785693
  • 935
  • 1
  • 8
  • 7

2 Answers2

2

You likely want to use psr-0 auto loading with a namespaced class. Here's a post on setting up laravel which says how to do that.

The Alpha
  • 143,660
  • 29
  • 287
  • 307
fideloper
  • 12,213
  • 1
  • 41
  • 38
0

If I understand your question correctly you are asking how to go about using the following syntax DB::q() using your own custom class...

Laravel uses Facades throughout its design which enables you to access classes from anywhere in your app using static style syntax (e.g. Input::get() or Route::get()). I note Fideloper has also provided an answer to your question... He has an excellent tutorial about how to wrap your own custom class in a Facade so you can use this syntax for your own classes and also sidestep the need to inject the dependency in any class that uses it (i.e. once set up correctly it can be called upon anywhere in your app).

Fideloper tutorial is here...

Hope that helps - Good luck

Ben Thompson
  • 4,743
  • 7
  • 35
  • 52