PHPackages                             pyaesoneaung/to-raw-sql - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. pyaesoneaung/to-raw-sql

ActiveLibrary[Database &amp; ORM](/categories/database)

pyaesoneaung/to-raw-sql
=======================

Get raw SQL from Laravel Query Builder

v1.1.3(2y ago)5611.1k4[2 PRs](https://github.com/PyaeSoneAungRgn/to-raw-sql/pulls)MITPHPPHP ^8.1

Since Feb 4Pushed 2y ago1 watchersCompare

[ Source](https://github.com/PyaeSoneAungRgn/to-raw-sql)[ Packagist](https://packagist.org/packages/pyaesoneaung/to-raw-sql)[ Docs](https://github.com/PyaeSoneAungRgn/to-raw-sql)[ RSS](/packages/pyaesoneaung-to-raw-sql/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (7)Dependencies (12)Versions (10)Used By (0)

[![Cover](https://camo.githubusercontent.com/923b07293bf1a01c29634288128298f63f58048b8ade435dfa7cd18d299f9b87/68747470733a2f2f696b2e696d6167656b69742e696f2f70796165736f6e6561756e672f6769746875622f746f2d7261772d73716c2f636f7665722e706e673f7570646174656441743d31363837343132303137393633)](https://camo.githubusercontent.com/923b07293bf1a01c29634288128298f63f58048b8ade435dfa7cd18d299f9b87/68747470733a2f2f696b2e696d6167656b69742e696f2f70796165736f6e6561756e672f6769746875622f746f2d7261772d73716c2f636f7665722e706e673f7570646174656441743d31363837343132303137393633)

[![GitHub Workflow Status](https://camo.githubusercontent.com/a523b75976f0c6441526f31fc81a0ab179441e5156b04dc66cad8ab3baa44486/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f50796165536f6e6541756e6752676e2f746f2d7261772d73716c2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d74657374)](https://github.com/PyaeSoneAungRgn/to-raw-sql/actions/workflows/run-tests.yml)[![Packagist Downloads](https://camo.githubusercontent.com/9792de842e82262f452c6b4f9efa17ffcfbafd2edb193a7406e3c77cdd1ece2a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70796165736f6e6561756e672f746f2d7261772d73716c)](https://packagist.org/packages/pyaesoneaung/to-raw-sql)

To Raw SQL
==========

[](#to-raw-sql)

⚠️ The `toRawSql()` function is included by default in Laravel 10.15.0. You don't need to install this package if your Laravel version is greater than 10.14.1 ⚠️

Get raw SQL from Laravel Query Builder and Eloquent Builder

Installation
------------

[](#installation)

```
composer require pyaesoneaung/to-raw-sql
```

Usage
-----

[](#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)"
```

```
DB::table('users')
   ->whereBetween('votes', [1, 100])
   ->toRawSql();

// "select * from `users` where `votes` between 1 and 100"
```

Version History
---------------

[](#version-history)

- 1.1.3
    - do not register the `toRawSql()` macro if the Laravel version is greater than 10.14.1
- 1.1.2
    - throw ToRawSqlException when encountering PostgreSQL jsonb operator errors
- 1.1.1
    - fixed boolean bind for pgsql
- 1.1.0
    - support Illuminate\\Database\\Query\\Builder
- 1.0.2
    - support DateTimeInterface bind
- 1.0.1
    - fixed string bind
- 1.0.0
    - support Illuminate\\Database\\Eloquent\\Builder

Testing
-------

[](#testing)

```
composer test
```

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity37

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 76.9% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~25 days

Recently: every ~37 days

Total

7

Last Release

1093d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b4a938e91069afb632288ccdb87813e19c0d0fc86189f73daa33464e0d2a0367?d=identicon)[pyaesoneaung](/maintainers/pyaesoneaung)

---

Top Contributors

[![PyaeSoneAungRgn](https://avatars.githubusercontent.com/u/44226349?v=4)](https://github.com/PyaeSoneAungRgn "PyaeSoneAungRgn (30 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (4 commits)")

---

Tags

databaseeloquentlaravelpyaesoneaungquery-builderraw-sqlsqllaravelpyaesoneaungto-raw-sql

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/pyaesoneaung-to-raw-sql/health.svg)

```
[![Health](https://phpackages.com/badges/pyaesoneaung-to-raw-sql/health.svg)](https://phpackages.com/packages/pyaesoneaung-to-raw-sql)
```

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k11.2M100](/packages/dedoc-scramble)[wnx/laravel-backup-restore

A package to restore database backups made with spatie/laravel-backup.

213421.0k2](/packages/wnx-laravel-backup-restore)[spatie/laravel-passkeys

Use passkeys in your Laravel app

471890.7k39](/packages/spatie-laravel-passkeys)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3914.6k](/packages/rawilk-profile-filament-plugin)[lacodix/laravel-model-filter

A Laravel package to filter, search and sort models with ease while fetching from database.

17558.6k](/packages/lacodix-laravel-model-filter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
