PHPackages                             lucasdotvin/laravel-database-queries-counter - 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. lucasdotvin/laravel-database-queries-counter

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

lucasdotvin/laravel-database-queries-counter
============================================

This package provides a simple trait to check how many queries a test suite has performed.

0.5.0(3y ago)25761[4 PRs](https://github.com/lucasdotvin/laravel-database-queries-counter/pulls)1MITPHPPHP ^7.4|^8.0|^8.1

Since Feb 5Pushed 2y ago1 watchersCompare

[ Source](https://github.com/lucasdotvin/laravel-database-queries-counter)[ Packagist](https://packagist.org/packages/lucasdotvin/laravel-database-queries-counter)[ Docs](https://github.com/lucasdotvin/laravel-database-queries-counter)[ GitHub Sponsors](https://github.com/lucasdotvin)[ RSS](/packages/lucasdotvin-laravel-database-queries-counter/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (5)Dependencies (11)Versions (10)Used By (1)

Laravel Database Queries Counter
================================

[](#laravel-database-queries-counter)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5b42761f218b6382ce3e739ec647e24937cc9be5c4d350f9adfeafc3a2eef4fc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c75636173646f7476696e2f6c61726176656c2d64617461626173652d717565726965732d636f756e7465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lucasdotvin/laravel-database-queries-counter)[![GitHub Tests Action Status](https://camo.githubusercontent.com/ceca189dc045282773f328fe40ec26632d81cecedc7680f59f9864d45205e34e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6c75636173646f7476696e2f6c61726176656c2d64617461626173652d717565726965732d636f756e7465722f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/lucasdotvin/laravel-database-queries-counter/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/ec8e0430ee553e6ab6b23ac1128ac0d6567761aeeadb058986cca1797548bed1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6c75636173646f7476696e2f6c61726176656c2d64617461626173652d717565726965732d636f756e7465722f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/lucasdotvin/laravel-database-queries-counter/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/39a81d81fb6d64833ac62c7b6eca44448d95cade63b89b7967f97457fb3efb13/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c75636173646f7476696e2f6c61726176656c2d64617461626173652d717565726965732d636f756e7465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lucasdotvin/laravel-database-queries-counter)

This package provides a simple way to check how many queries a test suite has performed.

> It is important to keep in mind that merely controlling how many queries you perform on the database is not enough to ensure your application has a good performance. This package does not intend to do it, instead, it is thought to help you prevent common mistakes (like N+1 queries).

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

[](#installation)

You can install the package via composer:

```
composer require lucasdotvin/laravel-database-queries-counter --dev
```

You can publish the traits if you want to extend them:

```
php artisan vendor:publish --tag="laravel-database-queries-counter-traits"
```

Usage
-----

[](#usage)

Add the `CountsQueries` trait to your test suite class to access the package methods, like `startCountingQueries`, `stopCountingQueries`, and `assertDatabaseQueriesCount`, as demonstrated below, where we assert that an index route does not perform N+1 queries to load the posts from a blog:

```
