PHPackages                             datalogix/laravel-builder-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. datalogix/laravel-builder-macros

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

datalogix/laravel-builder-macros
================================

A set of useful Laravel builder macros.

v4.1.0(1mo ago)2906—10%1MITPHPPHP ^8.2CI passing

Since Dec 2Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/datalogix/laravel-builder-macros)[ Packagist](https://packagist.org/packages/datalogix/laravel-builder-macros)[ Docs](https://github.com/datalogix/laravel-builder-macros)[ GitHub Sponsors](https://github.com/ricardogobbosouza)[ Fund](https://opencollective.com/ricardogobbosouza)[ RSS](/packages/datalogix-laravel-builder-macros/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (10)Versions (10)Used By (1)

Laravel Builder Macros
======================

[](#laravel-builder-macros)

[![Latest Stable Version](https://camo.githubusercontent.com/ecea0f0531438acadca3318adfb0fb23faf77342258e33ef25d40eefb3b88e33/68747470733a2f2f706f7365722e707567782e6f72672f646174616c6f6769782f6c61726176656c2d6275696c6465722d6d6163726f732f76657273696f6e)](https://packagist.org/packages/datalogix/laravel-builder-macros)[![Total Downloads](https://camo.githubusercontent.com/1cfe13be2aeae38fe9ffe3bed7875afdc494b20f1462a1b9235507e27e182d79/68747470733a2f2f706f7365722e707567782e6f72672f646174616c6f6769782f6c61726176656c2d6275696c6465722d6d6163726f732f646f776e6c6f616473)](https://packagist.org/packages/datalogix/laravel-builder-macros)[![tests](https://github.com/datalogix/laravel-builder-macros/workflows/tests/badge.svg)](https://github.com/datalogix/laravel-builder-macros/actions)[![StyleCI](https://camo.githubusercontent.com/66d0f9140d496e020c38b2ad476cf3213000f69c79291c1bb4b911760d140226/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3331363736313139342f736869656c643f7374796c653d666c6174)](https://github.styleci.io/repos/316761194)[![codecov](https://camo.githubusercontent.com/7b1b067ca81bf323872450fc080fe77022ba4be48ba16b6a699d56f440f4727c/68747470733a2f2f636f6465636f762e696f2f67682f646174616c6f6769782f6c61726176656c2d6275696c6465722d6d6163726f732f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/datalogix/laravel-builder-macros)[![License](https://camo.githubusercontent.com/974bda606f3a6674c301fa951d1328e5a49c1785050b36dd78f4d121d460e189/68747470733a2f2f706f7365722e707567782e6f72672f646174616c6f6769782f6c61726176656c2d6275696c6465722d6d6163726f732f6c6963656e7365)](https://packagist.org/packages/datalogix/laravel-builder-macros)

> A set of useful Laravel builder macros.

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

[](#installation)

You can install the package via composer:

```
composer require datalogix/laravel-builder-macros
```

The package will automatically register itself.

Macros
------

[](#macros)

- [`addSubSelect`](#addSubSelect)
- [`defaultSelectAll`](#defaultSelectAll)
- [`filter`](#filter)
- [`joinRelation`](#joinRelation)
- [`leftJoinRelation`](#leftJoinRelation)
- [`map`](#map)
- [`whereLike`](#whereLike)

### `addSubSelect`

[](#addsubselect)

Add a select sub query.

```
// Params: $column, $query
$query->addSubSelect('primary_address_id',
    Address::select('id')
        ->where('user_id', $user->id)
        ->primary()
);

// It adds primary_address_id to the result set
```

### `defaultSelectAll`

[](#defaultselectall)

It selects all columns from the query. Useful for queries with joins and additional selects.

```
$query->defaultSelectAll()
    ->join('contacts', 'users.id', '=', 'contacts.user_id')
    ->addSelect('contacts.name as contact_name');
```

### `filter`

[](#filter)

Filter in your models.

```
$query->filter(['name' => 'john'])->get();

// Returns all results where name includes `john`
```

You can also supply an array of columns to filter in:

```
$query->filter(['name' => 'john', 'contact.email' => '@'])->get();

// Returns all results where name includes `john` or contact.email includes `@`
```

You can use `$request->all()`:

```
$query->filter($request->all())->get();
```

### `joinRelation`

[](#joinrelation)

A query way to join relations.

```
// Params: $relationName, $operator
$query->joinRelation('contact');
```

### `leftJoinRelation`

[](#leftjoinrelation)

A query to left join relations.

```
// Params: $relationName, $operator
$query->leftJoinRelation('contact');
```

### `map`

[](#map)

A direct method to retrieve the results and map it.

```
$userIds = $query->where('user_id', 10)->map(function ($user) {
    return $user->id;
});

// Returns a collection
```

### `whereLike`

[](#wherelike)

Search in your models with the `LIKE` operator.

```
$query->whereLike('title', 'john')->get();

// Returns all results where title includes `john`
```

```
$query->whereLike('title', 'john', false)->get();

// Returns all results where title ends with `john`
```

```
$query->whereLike('title', 'john', true, false)->get();

// Returns all results where title starts with `john`
```

You can also supply an array of columns to search in:

```
$query->whereLike(['title', 'contact.name'], 'john')->get();

// Returns all results where title or contact.name includes `john`
```

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance89

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity72

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~242 days

Total

9

Last Release

55d ago

Major Versions

v1.0.0 → v2.0.02021-10-19

v2.2.0 → v3.0.02023-07-18

v3.2.0 → v4.0.02025-04-14

PHP version history (4 changes)v1.0.0PHP ^7.2|^8.0

v2.0.0PHP ^7.3|^8.0

v3.0.0PHP ^7.4|^8.0

v4.0.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/64f33efa07f410c2b5e41054fcf2bd13369172846b9fd71420d2162e90bb6a1a?d=identicon)[ricardogobbosouza](/maintainers/ricardogobbosouza)

---

Top Contributors

[![ricardogobbosouza](https://avatars.githubusercontent.com/u/13064722?v=4)](https://github.com/ricardogobbosouza "ricardogobbosouza (41 commits)")

---

Tags

laravelsqlquerybuildermacros

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/datalogix-laravel-builder-macros/health.svg)

```
[![Health](https://phpackages.com/badges/datalogix-laravel-builder-macros/health.svg)](https://phpackages.com/packages/datalogix-laravel-builder-macros)
```

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[rennokki/laravel-eloquent-query-cache

Adding cache on your Laravel Eloquent queries' results is now a breeze.

1.1k4.0M14](/packages/rennokki-laravel-eloquent-query-cache)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[mehdi-fathi/eloquent-filter

Eloquent Filter adds custom filters automatically to your Eloquent Models in Laravel.It's easy to use and fully dynamic, just with sending the Query Strings to it.

450191.6k1](/packages/mehdi-fathi-eloquent-filter)[cerbero/sql-dumper

Laravel package to dump SQL queries.

247.6k](/packages/cerbero-sql-dumper)

PHPackages © 2026

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