Skip to content

An easy way to print queries in Laravel ๐Ÿ–จ๏ธ

License

Notifications You must be signed in to change notification settings

loburets/laravel-query-printer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

11 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ–จ๏ธ Laravel Query Printer

An easy way to print Laravel queries

๐Ÿ“Œ Example

// Enable query log
\DB::enableQueryLog();

// Use whatever queries you want to debug:
User::where('email', '[email protected]')->where('verified', true)->first();
User::where('id', '<', '5')->get();

// See what the queries were executed
\QueryPrinter::printQueryLog();

๐Ÿ”น Output without this package:

Without Package

๐Ÿ”น Output with this package:

With Package

Now you can simply copy and execute the query without struggling with bindings ๐Ÿ™Œ


๐Ÿš€ Installation

composer require loburets/laravel-query-printer

For Laravel < 5.5, add the alias in config/app.php:

'QueryPrinter' => Loburets\LaravelQueryPrinter\Facade::class,

๐Ÿ› ๏ธ Usage

โœ… Printing a Query Builder instance

You can print a query before execution:

    // Build your query, but don't call ->first(), ->get() etc. So it is an instance of the Query Builder here:
    $query = \Model::where()->join()->etc();

    // Print the generated SQL
    \QueryPrinter::print($query);

โœ… Printing executed queries from query logs

You can also print queries after they have been executed:

    // Enable the Query log:
    \DB::enableQueryLog();

    // Do any actions which you want to be logged:
    $results = \Model::where()->join()->etc()->get();

    // Print all the executed queries
    \QueryPrinter::printQueryLog();

Now debugging Laravel queries is easier than ever! ๐ŸŽฏ

About

An easy way to print queries in Laravel ๐Ÿ–จ๏ธ

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages