PHPackages                             abdelilah-ezzouini/db-macros - 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. abdelilah-ezzouini/db-macros

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

abdelilah-ezzouini/db-macros
============================

A Laravel package that extends the DB facade with powerful macros to enhance database query building and manipulation in your Laravel applications

1201PHPCI passing

Since Apr 8Pushed 1y ago1 watchersCompare

[ Source](https://github.com/AbdelilahEzzouini/laravel-db-macros)[ Packagist](https://packagist.org/packages/abdelilah-ezzouini/db-macros)[ RSS](/packages/abdelilah-ezzouini-db-macros/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel DB Macros
=================

[](#laravel-db-macros)

A Laravel package that provides useful DB macros for query building.

Overview
--------

[](#overview)

The `binding` macro extends Laravel's database functionality by providing a more intuitive way to work with SQL queries using named parameters. This approach offers several advantages:

### Key Features

[](#key-features)

- **Named Parameters**: Use descriptive parameter names (`:param_name`) instead of positional placeholders (`?`), making your queries more readable and maintainable.
- **Array Parameter Support**: Easily include arrays in your IN clauses with the special `[:array_param]` syntax.
- **Flexible Statement Types**: Execute different types of SQL operations (SELECT, INSERT, UPDATE, DELETE) using the same consistent syntax.
- **SQL Injection Protection**: All parameters are properly escaped and bound, maintaining the security of your database operations.
- **Simplified Complex Queries**: Write complex SQL queries with multiple parameters without losing track of parameter order.

This macro bridges the gap between raw SQL flexibility and Laravel's query builder safety, giving you the best of both worlds for situations where the query builder might be too limiting.

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

[](#installation)

You can install the package via composer:

```
composer require abdelilah-ezzouini/db-macros:dev-main
```

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

[](#configuration)

After installing the package, the service provider will be automatically registered thanks to Laravel's package auto-discovery.

If you're using Laravel without auto-discovery, add the service provider to the `providers` array in `config/app.php`:

```
'providers' => [
    // ...
    AbdelilahEzzouini\DbMacros\DbMacrosServiceProvider::class
    // ...
]
```

Usage
-----

[](#usage)

The package provides a `binding` macro for the DB facade that allows you to use named parameters in your SQL queries.

### Basic Usage

[](#basic-usage)

```
use Illuminate\Support\Facades\DB;

$results = DB::binding('SELECT * FROM users WHERE id = :id', [
    'id' => 1
]);
```

### Array Parameters

[](#array-parameters)

You can also use array parameters with the `[:param]` syntax:

```
$results = DB::binding('SELECT * FROM users WHERE id IN ([:ids])', [
    'ids' => [1, 2, 3]
]);
```

### Statement Type

[](#statement-type)

By default, the `binding` macro uses the `select` statement type based on the DB Facades. You can specify a different statement type as the third parameter:

```
$results = DB::binding('UPDATE users SET name = :name WHERE id IN :id', [
    'name' => 'test user',
    'id' => 1
],'affectingStatement');
```

Testing
-------

[](#testing)

To run the tests for this package, you can use PHPUnit:

```
vendor/bin/phpunit
```

Copyright (c) Abdelilah Ezzouini

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity15

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

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

---

Top Contributors

[![AbdelilahEzzouini](https://avatars.githubusercontent.com/u/23565045?v=4)](https://github.com/AbdelilahEzzouini "AbdelilahEzzouini (3 commits)")

---

Tags

illuminateilluminate-databaselaravellaravel-frameworklaravel-package

### Embed Badge

![Health badge](/badges/abdelilah-ezzouini-db-macros/health.svg)

```
[![Health](https://phpackages.com/badges/abdelilah-ezzouini-db-macros/health.svg)](https://phpackages.com/packages/abdelilah-ezzouini-db-macros)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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