PHPackages                             guanguans/laravel-soar - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. guanguans/laravel-soar

ActiveLaravel[Testing &amp; Quality](/categories/testing)

guanguans/laravel-soar
======================

SQL optimizer and rewriter for laravel. - laravel 的 SQL 优化器和重写器。

5.2.0(1mo ago)2227.8k↓41.7%9MITPHPPHP &gt;=8.1CI passing

Since Jun 27Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/guanguans/laravel-soar)[ Packagist](https://packagist.org/packages/guanguans/laravel-soar)[ Docs](https://github.com/guanguans/laravel-soar)[ Fund](https://guanguans.github.io/sponsors)[ RSS](/packages/guanguans-laravel-soar/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (128)Versions (97)Used By (0)

[![](docs/soar-bar.gif)](docs/soar-bar.gif)[![](docs/commands.gif)](docs/commands.gif)laravel-soar
============

[](#laravel-soar)

> SQL optimizer and rewriter for laravel. - laravel 的 SQL 优化器和重写器。

[简体中文](README-zh_CN.md) | [ENGLISH](README.md)

[![tests](https://github.com/guanguans/laravel-soar/actions/workflows/tests.yml/badge.svg)](https://github.com/guanguans/laravel-soar/actions/workflows/tests.yml)[![php-cs-fixer](https://github.com/guanguans/laravel-soar/actions/workflows/php-cs-fixer.yml/badge.svg)](https://github.com/guanguans/laravel-soar/actions/workflows/php-cs-fixer.yml)[![codecov](https://camo.githubusercontent.com/42f2914da4194b567260027fea2a34276ee41bbeb7b3e4a11b64f0af023c18b2/68747470733a2f2f636f6465636f762e696f2f67682f6775616e6775616e732f6c61726176656c2d736f61722f67726170682f62616467652e7376673f746f6b656e3d45574247384756344a44)](https://codecov.io/gh/guanguans/laravel-soar)[![Latest Stable Version](https://camo.githubusercontent.com/84b5b9f25d8558954156246af9ec7cab3d6479e8ec732369ab4f0b0a871a05a4/68747470733a2f2f706f7365722e707567782e6f72672f6775616e6775616e732f6c61726176656c2d736f61722f76)](https://packagist.org/packages/guanguans/laravel-soar)[![GitHub release (with filter)](https://camo.githubusercontent.com/e64e5fab64009c8b01dacce17e1b009fef323e6d42c201f472408d286836d834/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f6775616e6775616e732f6c61726176656c2d736f6172)](https://github.com/guanguans/laravel-soar/releases)[![Total Downloads](https://camo.githubusercontent.com/50fafe8d89695c7ead5829fc7f3e47d02cbe7fc4ca70fdb4e32e75430fec3c22/68747470733a2f2f706f7365722e707567782e6f72672f6775616e6775616e732f6c61726176656c2d736f61722f646f776e6c6f616473)](https://packagist.org/packages/guanguans/laravel-soar)[![License](https://camo.githubusercontent.com/2f9b2c8b2412b22c4ffa22e4cf9d5045ab1985d7ee8dc892d64415186bc7c24a/68747470733a2f2f706f7365722e707567782e6f72672f6775616e6775616e732f6c61726176656c2d736f61722f6c6963656e7365)](https://packagist.org/packages/guanguans/laravel-soar)

Features
--------

[](#features)

- Supports heuristic rule suggestions, index rule suggestions, and `EXPLAIN` information interpretation
- Support calling query builder `Mixin` methods for convenient dumping of rule suggestions
- Automatically monitor output rule suggestions to configured outputs

Related Links
-------------

[](#related-links)

-
-

Requirement
-----------

[](#requirement)

- PHP &gt;= 8.1

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

[](#installation)

```
composer require guanguans/laravel-soar --dev --ansi -v
```

Configuration
-------------

[](#configuration)

### Publish files(optional)

[](#publish-filesoptional)

```
php artisan vendor:publish --provider="Guanguans\\LaravelSoar\\SoarServiceProvider"
```

### ⚠️ When running in a unix OS non-cli environment, may throw Fatal error: ...Exit Code: 2(Misuse of shell builtins)

[](#warning-when-running-in-a-unix-os-non-cli-environment-may-throw-fatal-error-exit-code-2misuse-of-shell-builtins)

#### Configure sudo password

[](#configure-sudo-password)

```
# Fatal error: Uncaught Guanguans\SoarPHP\Exceptions\ProcessFailedException: The command "'/Users/yaozm/Documents/develop/soar-php/bin/soar.darwin-amd64' '-report-type=json' '-query=select * from users;'" failed. Exit Code: 2(Misuse of shell builtins) Working directory: /Users/yaozm/Documents/develop/soar-php Output: ================ Error Output: ================ panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1938665] goroutine 1 [running]: github.com/pingcap/tidb/util/memory.MemTotalNormal() pkg/mod/github.com/pingcap/tidb@v1.1.0-beta.0.20210601085537-5d7c852770eb/util/memory/meminfo.go:41 +0x65 github.com/pingcap/tidb/util/memory.init.0() pkg/mod/github.com/pingcap/tidb@v1.1.0-beta.0.20210601085537-5d7c852770eb/util/memory/meminfo.go:134 +0x175 in /Users/yaozm/Documents/develop/soar-php/src/Concerns/WithRunable.php:36 Stack trace: #0 /Users/yaozm/Documents/develop/soar-php/test.php(163): Guanguans\SoarPHP\Soar->run() #1 /User in /Users/yaozm/Documents/develop/soar-php/src/Concerns/WithRunable.php on line 36
SOAR_SUDO_PASSWORD='your sudo password' # Set a sudo password to run the soar command with sudo to avoid the above errors.
```

#### [Or configure sudoers](https://github.com/guanguans/soar-php#or-configure-sudoers)

[](#or-configure-sudoers)

Usage
-----

[](#usage)

### Enable to automatically output SQL optimization suggestions

[](#enable-to-automatically-output-sql-optimization-suggestions)

**details**#### Configure `SOAR_ENABLED`

[](#configure-soar_enabled)

```
SOAR_ENABLED=true
```

#### Or configure [`soar.enabled`](config/soar.php)

[](#or-configure-soarenabled)

```
