Download the PHP package bigenergy/laravel-nplusone-baseline without Composer

On this page you can find all versions of the php package bigenergy/laravel-nplusone-baseline. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-nplusone-baseline

Laravel N+1 Baseline

Catch N+1 regressions in CI, on a codebase that already has hundreds of them.

tests


The problem

You fix an N+1 on the orders endpoint. 120 queries become 8. Three months later somebody adds {{ $order->manager->name }} to a Blade template. Nothing breaks, tests stay green, the diff is one harmless line — and the endpoint is back to 120 queries. You find out six months later when a user complains the page is slow.

Laravel already ships the detection mechanism for this. Model::preventLazyLoading() throws a LazyLoadingViolationException the moment a relation is lazy loaded, and Model::handleLazyLoadingViolationUsing() lets you replace that exception with your own callback. This package does not reimplement any of that — it builds the two things on top that are missing when you try to use strict mode on a real project:

  1. It collects instead of throwing. Strict mode aborts on the first violation, so on an existing codebase you learn about violation #1 out of 300 and nothing else. Here the suite runs to completion and you get the whole picture at once.
  2. It has a baseline. The 300 violations you already have get recorded as accepted. CI stays quiet about them and fails on #301. This is the part that makes the check adoptable in an afternoon rather than after a multi-week cleanup — the same reason PHPStan ships a baseline.

Net effect: N+1s stop being found in production and start being found in the pull request.

Installation

Register the PHPUnit extension in phpunit.xml so violations can be attributed to the test that triggered them:

Optionally publish the config:

Adopting it on an existing project

That is the whole adoption step. Nothing had to be fixed first.

In CI

nplusone:check exits non-zero only when the run contains a fingerprint that is not in the baseline:

When somebody fixes an N+1, its baseline entry is reported as stale so the file can be pruned and does not keep silently granting permission for something that was cleaned up months ago. Stale entries do not fail the build unless you pass --prune.

Design decisions

Fingerprint is Model::relation, not the call site. Call sites and test names move during refactoring; the model/relation pair does not. Both are still recorded and shown in the report so you know where to look, but they do not participate in the comparison.

Counts are not compared. The same endpoint lazy loading the same relation fires a different number of times depending on how many rows your factories happened to create. Comparing counts produces red builds that have nothing to do with the code under review, which is the fastest way to get a CI check disabled.

Your test suite is the scanner. Your tests already exercise the controllers that cause the lazy loads, so no separate crawling step or instrumentation is needed. The flip side is the obvious one: coverage of this check equals coverage of your test suite. Code no test touches is invisible to it.

Testing environment only. This is a CI tool, not an APM. For finding N+1s in production traffic you want something that samples real requests; Telescope writes inline to the request lifecycle and does not aggregate, so it is not that either.

Requirements

Pest works — it runs on PHPUnit, so the extension applies unchanged.

Known limitations

License

MIT


All versions of laravel-nplusone-baseline with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/console Version ^11.0|^12.0
illuminate/database Version ^11.0|^12.0
illuminate/support Version ^11.0|^12.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package bigenergy/laravel-nplusone-baseline contains the following files

Loading the files please wait ...