DEV Community

Cover image for Get raw SQL from Laravel Query Builder
Pyae Sone Aung
Pyae Sone Aung

Posted on

Get raw SQL from Laravel Query Builder

GitHub logo PyaeSoneAungRgn / to-raw-sql

Get raw SQL from Laravel Query Builder

GitHub Workflow Status

To Raw SQL

Get raw SQL from Laravel Query Builder

Installation

composer require pyaesoneaung/to-raw-sql
Enter fullscreen mode Exit fullscreen mode

Usage

User::where('votes', '>', 100)
    ->orWhere(function ($query) {
        $query->where('name', 'Abigail')
            ->where('votes', '>', 50);
    })
    ->toRawSql();

// "select * from `users` where `votes` > 100 or (`name` = Abigail and `votes` > 50)"
Enter fullscreen mode Exit fullscreen mode

Testing

composer test
Enter fullscreen mode Exit fullscreen mode

License

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




You can get raw SQL from Laravel Query Builder using PyaeSoneAungRgn/to-raw-sql

Top comments (0)