A Laravel package to output a specific sql to your favourite debugging tool. The supported log output is Laravel Telescope, Laravel Log, Ray, Clockwork, Laravel Debugbar and your browser.

Last update: Jun 10, 2022

showsql

Tests Downloads

Laravel showsql

A Laravel package to output a specific sql to your favourite debugging tool, your browser or your log file.

Use case

You often want to draw the attention and look into one single sql while you are developing. You can look up your sql in your favourite debugging tool in the sql tab , but most of the time your sql is not the only sql executed ... So the searching begins. With this package you can add showSql() to your QueryBuilder and the single sql will be outputted to the logging of your debug tool.

The supported log output is Laravel Telescope, Laravel Log, Ray, Clockwork, Laravel Debugbar and your browser. By default, showSql will try to log to Ray, Clockwork or the Laravel Debugbar if one of them is installed. If all installed it will be output to all. If you want your own log implementation you can pass a callback to showSql.

If you want to change this behaviour you can publish the config file and change it.

Installation

composer require dietercoopman/laravel-showsql --dev

Examples

# With the Eloquent Builder

Menu::showSql()->get();

Menu::whereId(1)->showSql()->get();

Menu::whereHas('status')->showSql()->get();

# With the Query Builder

DB::table('menus')->where('id', '=', 10)->showSql()->get();

DB::table('menus')->join('statuses', 'statuses.id', '=', 'menus.status_id')
                 ->showSql()
                 ->get();

# With a callback 

$callback = function(string $sql){
  Log::info($sql);
};

DB::table('products')->where('id', '=', 1)->show($callback)->get();

This is an example log output

showsql example

Configuration

You can publish the config file with the following command

php artisan vendor:publish --tag=showsql-config 

Laravel showsql is default configured to output to ray,clockwork and laravel debugbar. If you want to change this you can do it in the published config file.

return [
    'to' => [
        'telescope' => false,
        'ray' => true,
        'clockwork' => true,
        'debugbar' => true,
        'log' => false,
        'browser' => false,
    ]
];

Why is this not available in the core of Laravel ?

I've created a pull request to the framework that has been declined. It adds too much extra logic to the framework itself. The queries as generated in this code are actual not the real statements as passed to your database engines. The real sql never lives in the framework. The query and bindings are passed separately to the database engine and constructed there. So there might be some edge cases. You can see my pull request here

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

GitHub

https://github.com/dietercoopman/laravel-showsql
You might also like...

Support for many missing PostgreSQL specific features

Support for many missing PostgreSQL specific features

Laravel supports many different databases and therefore has to limit itself to the lowest common denominator of all databases. PostgreSQL, however, of

Jul 3, 2022

Phpstan-dba - database handling related class reflection extension for PHPStan & framework-specific rules

database handling class reflection extension for PHPStan This extension provides following features: PDO-query knows the array shape of the returned

Jun 21, 2022

Symfony 5.2 + api platform project with ELK stack + elastic FileBeats for the log management. All running in 7 docker containers: nginx, php 8, mysql, elastic search, logstash, kibana, fileBeats.

Symfony with ELK and Elastic FileBeats Stack Prerequisites: Make sure that docker and docker-compose are installed in your machine and available for y

May 20, 2022

Adminer database management tool for your Laravel application.

Laravel Adminer Adminer database management tool for your Laravel application. Table of Contents Introduction Features Installation CSRF token middlew

Jun 18, 2022

Database lookup tool in php, skidlookup has not been claimed so if u want to use this src all right's go to u, idea came from fedsearch

Database lookup tool in php, skidlookup has not been claimed so if u want to use this src all right's go to u, idea came from fedsearch

skidlookup Database lookup tool in php, skidlookup has not been claimed so if u want to use this src, all right's go to u, idea came from fedsearch in

Dec 1, 2021

Database lookup tool in php, skidlookup has not been claimed so if u want to use this src all right's go to u, idea came from fedsearch

Database lookup tool in php, skidlookup has not been claimed so if u want to use this src all right's go to u, idea came from fedsearch

skidlookup Database lookup tool in php, skidlookup has not been claimed so if u want to use this src, all right's go to u, idea came from fedsearch in

Dec 1, 2021

Static testing tool for psalm plugins

Psalm test Static testing tool for psalm plugins. Installation $ composer require --dev klimick/psalm-test $ vendor/bin/psalm-plugin enable klimick/ps

May 31, 2022

RockMongo is a MongoDB administration tool, written in PHP 5.

Introduction -------------------------------------- RockMongo is a MongoDB administration tool, written in PHP 5, very easy to install and use. Inst

Jun 10, 2022

phpSleekDBAdmin - a web-based SleekDB database admin tool written in PHP

phpSleekDBAdmin - a web-based SleekDB database admin tool written in PHP

phpSleekDBAdmin is a web-based SleekDB database admin tool written in PHP. Following in the spirit of the flat-file system used by SleekDB, phpSleekDBAdmin consists of a single source file, phpsleekdbadmin.php. The interface and user experience is comparable to that of phpLiteAdmin and phpMyAdmin.

Feb 18, 2022
Comments
  • 1. minimum versions required

    I can't see anywhere minimum version sequired, so I tried to install, but it seems PHP 7.4 is not enough :-(

    "Problem 1 - dietercoopman/laravel-showsql v1.1 requires php ^8.0 -> your php version (7.4.26) does not satisfy that requirement."

    Is this correct?

    Reviewed by alagoroVigo at 2021-12-13 18:36
  • 2. Showsql need an arguments

    Hello Dieter I'm trying the package and this happens, am I doing something wrong !!

    $res = Reservation::showSql()->get();

    "message": "Too few arguments to function Illuminate\Database\Query\Builder::Dietercoopman\Showsql\{closure}(), 0 passed in vendor/laravel/framework/src/Illuminate/Macroable/Traits/Macroable.php on line 114 and exactly 1 expected",

    Reviewed by baselrabia at 2021-11-25 11:08
  • 3. Incompatibility with Laravel ide-helper.

    As you may be aware, this packages is widely use. When I run ide-helper commands I get the following output image

    I highly advise adding support for this package.

    Reviewed by Temepest74 at 2021-12-16 13:48
  • 4. Eager loading using with() not supported

    Queries fired by using the with method are not logged. For example, the query below will not show any query related to fetching the users:

    $post->comments()->with('users')->showSql()->get()
    
    Reviewed by wvdongen at 2022-04-13 17:28
Related tags
Independent query builders for MySQL, PostgreSQL, SQLite, and Microsoft SQL Server.

Aura.SqlQuery Provides query builders for MySQL, Postgres, SQLite, and Microsoft SQL Server. These builders are independent of any particular database

Jun 21, 2022
A validating SQL lexer and parser with a focus on MySQL dialect.

SQL Parser A validating SQL lexer and parser with a focus on MySQL dialect. Code status Installation Please use Composer to install: composer require

Jun 23, 2022
A php securised login system, using Hash, Salt and prevent from SQL Injections

A Basic Secure Login Implementation Hashed & Salted password ( only hashed in ShA-512 for now ) No SQL injection possible Prevent XSS attacks from the

Mar 6, 2022
Tiny php mysql lib (PDO-based) with handy fetch/update functionality, supports both SQL and parametric queries

Micro PHP mysql lib (~ 200 lines of code) with ultra powerful CRUD for faster than ever development: parametric fetch/insert/update/delete (based on a

Feb 22, 2022
SQL to Laravel Query Builder

Marwan - SQL To Laravel Builder SQL to Laravel Query Builder, A Converter written in PHP Features Converts SQL Queries to Laravel Query Builder. Assis

Jun 12, 2022
SQL database access through PDO.

Aura.Sql Provides an extension to the native PDO along with a profiler and connection locator. Because ExtendedPdo is an extension of the native PDO,

May 23, 2022
ATK Data - Data Access Framework for high-latency databases (Cloud SQL/NoSQL).
ATK Data - Data Access Framework for high-latency databases (Cloud SQL/NoSQL).

ATK Data - Data Model Abstraction for Agile Toolkit Agile Toolkit is a Low Code framework written in PHP. Agile UI implement server side rendering eng

Jun 3, 2022
A SQL query builder with zero dependencies

Latitude Query Builder A SQL query builder with zero dependencies. Attempts to be PSR-1, PSR-2, and PSR-4 compliant. Install composer require latitude

Jun 24, 2022
Extract SQL statements from migrations

This is my package MigrationToSql To install: composer require bcleverly/migrationtosql --dev This repo is here to help you extract the SQL queries fr

Apr 15, 2022
A minimalistic implementation of asynchronous SQL for PHP.

libSQL A minimalistic implementation of asynchronous SQL for PHP. Installation via DEVirion Install the DEVirion plugin and start your server. This wi

Apr 9, 2022