{"id":33956060,"url":"https://github.com/sebdesign/blade-sql-formatter","last_synced_at":"2025-12-12T20:19:09.536Z","repository":{"id":62541660,"uuid":"431625062","full_name":"sebdesign/blade-sql-formatter","owner":"sebdesign","description":"Display formatted SQL queries in your Laravel views","archived":false,"fork":false,"pushed_at":"2025-03-01T11:42:01.000Z","size":58,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-30T10:27:45.570Z","etag":null,"topics":["blade","doctrine","laravel","query","sql"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sebdesign.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-24T20:52:50.000Z","updated_at":"2025-03-01T11:42:04.000Z","dependencies_parsed_at":"2024-04-10T10:52:43.824Z","dependency_job_id":null,"html_url":"https://github.com/sebdesign/blade-sql-formatter","commit_stats":{"total_commits":15,"total_committers":3,"mean_commits":5.0,"dds":"0.19999999999999996","last_synced_commit":"0303092366be08dfa01692c3249b3a3bc89788fb"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":"spatie/package-skeleton-laravel","purl":"pkg:github/sebdesign/blade-sql-formatter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebdesign%2Fblade-sql-formatter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebdesign%2Fblade-sql-formatter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebdesign%2Fblade-sql-formatter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebdesign%2Fblade-sql-formatter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sebdesign","download_url":"https://codeload.github.com/sebdesign/blade-sql-formatter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sebdesign%2Fblade-sql-formatter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27690726,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-12T02:00:06.775Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blade","doctrine","laravel","query","sql"],"created_at":"2025-12-12T20:19:05.703Z","updated_at":"2025-12-12T20:19:09.531Z","avatar_url":"https://github.com/sebdesign.png","language":"PHP","readme":"# Display formatted SQL queries in your Laravel views\n\n[![GitHub license](https://img.shields.io/github/license/sebdesign/blade-sql-formatter)](https://github.com/sebdesign/blade-sql-formatter/blob/main/LICENSE.md)\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/sebdesign/blade-sql-formatter.svg)](https://packagist.org/packages/sebdesign/blade-sql-formatter)\n[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/sebdesign/blade-sql-formatter/run-tests.yml?branch=main\u0026label=tests)](https://github.com/sebdesign/blade-sql-formatter/actions/workflows/run-tests.yml?query=branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/sebdesign/blade-sql-formatter/fix-php-code-style-issues.yml?branch=main\u0026label=code%20style)](https://github.com/sebdesign/blade-sql-formatter/actions/workflows/fix-php-code-style-issues.yml?query=branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/sebdesign/blade-sql-formatter.svg)](https://packagist.org/packages/sebdesign/blade-sql-formatter)\n\nA small Laravel package for formatting SQL statements and files inside your Blade templates.\n\nThis package uses [`doctrine/sql-formatter`](https://github.com/doctrine/sql-formatter) to indent and add line breaks in addition to syntax highlighting.\n\n## Installation\n\n\u003e **Requires [PHP 8.1+](https://php.net/releases) and [Laravel 10+](https://laravel.com/docs/10.x/releases)**\n\nYou can install the package via composer:\n\n```bash\ncomposer require sebdesign/blade-sql-formatter\n```\n\nYou can publish the config file with:\n\n```bash\nphp artisan vendor:publish --tag=\"blade-sql-formatter-config\"\n```\n\nThis is the contents of the published config file:\n\n```php\n\u003c?php\n\nuse Doctrine\\SqlFormatter\\HtmlHighlighter;\n\nreturn [\n    'highlighter' =\u003e HtmlHighlighter::class,\n\n    'html_attributes' =\u003e [\n        HtmlHighlighter::HIGHLIGHT_QUOTE =\u003e 'style=\"color: blue;\"',\n        HtmlHighlighter::HIGHLIGHT_BACKTICK_QUOTE =\u003e 'style=\"color: purple;\"',\n        HtmlHighlighter::HIGHLIGHT_RESERVED =\u003e 'style=\"font-weight:bold;\"',\n        HtmlHighlighter::HIGHLIGHT_BOUNDARY =\u003e '',\n        HtmlHighlighter::HIGHLIGHT_NUMBER =\u003e 'style=\"color: green;\"',\n        HtmlHighlighter::HIGHLIGHT_WORD =\u003e 'style=\"color: #333;\"',\n        HtmlHighlighter::HIGHLIGHT_ERROR =\u003e 'style=\"background-color: red;\"',\n        HtmlHighlighter::HIGHLIGHT_COMMENT =\u003e 'style=\"color: #aaa;\"',\n        HtmlHighlighter::HIGHLIGHT_VARIABLE =\u003e 'style=\"color: orange;\"',\n        HtmlHighlighter::HIGHLIGHT_PRE =\u003e 'style=\"color: black; background-color: white;\"',\n    ],\n\n    'use_pre' =\u003e true,\n\n    'indent_string' =\u003e '  ',\n];\n```\n\nFeel free to customize the style of each token. You can use inline styles or CSS classes, even Tailwind CSS. Check out the demo on [Tailwind Play](https://play.tailwindcss.com/JXXKktftlS).\n\n## Usage\n\nInput:\n\n```\nselect * from `users` where `id` = 1 limit 1\n```\n\nOutput:\n\n\u003cpre style=\"color: black; background-color: white;\"\u003e\u003cspan style=\"font-weight:bold;\"\u003eselect\u003c/span\u003e\n  \u003cspan \u003e*\u003c/span\u003e\n\u003cspan style=\"font-weight:bold;\"\u003efrom\u003c/span\u003e\n  \u003cspan style=\"color: purple;\"\u003e`users`\u003c/span\u003e\n\u003cspan style=\"font-weight:bold;\"\u003ewhere\u003c/span\u003e\n  \u003cspan style=\"color: purple;\"\u003e`id`\u003c/span\u003e \u003cspan \u003e=\u003c/span\u003e \u003cspan style=\"color: green;\"\u003e1\u003c/span\u003e\n\u003cspan style=\"font-weight:bold;\"\u003elimit\u003c/span\u003e\n  \u003cspan style=\"color: green;\"\u003e1\u003c/span\u003e\n\u003c/pre\u003e\n\n### View component\n\n```html\n\u003c!-- Formatting and syntax highlighting --\u003e\n\u003cx-sql\u003e\n    select * from `users` where `id` = 1 limit 1\n\u003c/x-sql\u003e\n\n\u003c!-- Component attributes --\u003e\n\u003cx-sql class=\"bg-gray-100 rounded-xl\"\u003e\n    select * from `users` where `id` = 1 limit 1\n\u003c/x-sql\u003e\n\n\u003c!-- Syntax highlighting only --\u003e\n\u003cx-sql :format=\"false\"\u003e\n    select * from `users` where `id` = 1 limit 1\n\u003c/x-sql\u003e\n\n\u003c!-- Formatting only --\u003e\n\u003cx-sql :highlight=\"false\"\u003e\n    select * from `users` where `id` = 1 limit 1\n\u003c/x-sql\u003e\n```\n\n### HTML Entity Encoding\n\nIf you use Blade's `{{ }}` echo statements inside the `\u003cx-sql\u003e` component, they will be sent through `htmlspecialchars` automatically.\nIf your SQL statement contains single `'` or double `\"` quotes, they will be double-encoded.\n\nFor example:\n\n```html\n@php($sql = \"select * from `users` where `email` = 'info@example.com'\")\n\n\u003cx-sql\u003e{{ $sql }}\u003c/x-sql\u003e\n```\n\nWill output:\n\n\u003cpre style=\"color: black; background-color: white;\"\u003e\u003cspan style=\"font-weight:bold;\"\u003eselect\u003c/span\u003e\n  \u003cspan \u003e*\u003c/span\u003e\n\u003cspan style=\"font-weight:bold;\"\u003efrom\u003c/span\u003e\n  \u003cspan style=\"color: purple;\"\u003e`users`\u003c/span\u003e\n\u003cspan style=\"font-weight:bold;\"\u003ewhere\u003c/span\u003e\n  \u003cspan style=\"color: purple;\"\u003e`email`\u003c/span\u003e \u003cspan \u003e=\u003c/span\u003e \u003cspan \u003e\u0026amp;\u003c/span\u003e \u003cspan style=\"color: #aaa;\"\u003e#039;info@example.com\u0026amp;#039;\u003c/span\u003e\u003c/pre\u003e\n\nIn order to address this, you can use raw echo statements `{!! !!}` on your own responsibility.\n\n\u003e Learn more about [displaying unescaped data](https://laravel.com/docs/8.x/blade#displaying-unescaped-data).\n\nFor example:\n\n```html\n@php($sql = \"select * from `users` where `email` = 'info@example.com'\")\n\n\u003cx-sql\u003e{!! $sql !!}\u003c/x-sql\u003e\n```\n\nWill output:\n\n\u003cpre style=\"color: black; background-color: white;\"\u003e\u003cspan style=\"font-weight:bold;\"\u003eselect\u003c/span\u003e\n  \u003cspan \u003e*\u003c/span\u003e\n\u003cspan style=\"font-weight:bold;\"\u003efrom\u003c/span\u003e\n  \u003cspan style=\"color: purple;\"\u003e`users`\u003c/span\u003e\n\u003cspan style=\"font-weight:bold;\"\u003ewhere\u003c/span\u003e\n  \u003cspan style=\"color: purple;\"\u003e`email`\u003c/span\u003e \u003cspan \u003e=\u003c/span\u003e \u003cspan style=\"color: blue;\"\u003e'info@example.com'\u003c/span\u003e\u003c/pre\u003e\n\n### Blade directive\n\n```html\n\u003c!-- Format the SQL statement string --\u003e\n@sql('select * from `users` where `id` = 1 limit 1')\n\n\u003c!-- Format the SQL statement block --\u003e\n@sql\n    select * from `users` where `id` = 1 limit 1\n@endsql\n```\n\n### Rendering and including views\n\nYou can render and include SQL files like Blade files inside your controllers and your views. The SQL files will be compiled as formatted and highlighted HTML files, and will be cached in the compiled view path, e.g.: `storage/framework/views`.\n\nIf you don't want to store you SQL files in the `resources/views` directory, you can load them from another location, by adding the path in the `paths` key of your `config/view.php` file.\n\nThe following example will use the `database/queries` directory to find SQL files:\n\n```php\nreturn [\n    'paths' =\u003e [\n        resource_path('views'),\n        database_path('queries'),\n    ],\n];\n```\n\nIf you prefer using a namespace to separate your Blade files from your SQL files, you can add one in the `boot` method of a service provider.\n\nThe following example will use the `database/queries` directory to find SQL files with the `sql::` namespace:\n\n\u003e In this case you don't need to add the path to `config/view.php`.\n\n```php\npublic function boot()\n{\n    $this-\u003eloadViewsFrom(database_path('queries'), 'sql');\n}\n```\n\nRender `database/queries/users/select-first-user.sql` from a controller.\n\n```php\npublic function show()\n{\n    return view('sql::users.select-first-user');\n}\n```\n\nInclude `database/queries/users/select-first-user.sql` within a Blade view.\n\n```php\n@include('sql::users.select-first-user')\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](.github/SECURITY.md) on how to report security vulnerabilities.\n\n## Credits\n\n-   [Sébastien Nikolaou](https://github.com/sebdesign)\n-   [Grégoire Paris](https://github.com/greg0ire)\n-   [Jeremy Dorn](https://github.com/jdorn)\n-   [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebdesign%2Fblade-sql-formatter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsebdesign%2Fblade-sql-formatter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsebdesign%2Fblade-sql-formatter/lists"}