PHPackages                             salamwaddah/laravel-relation-parser - 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. salamwaddah/laravel-relation-parser

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

salamwaddah/laravel-relation-parser
===================================

Easily load model relations from frontend without changing your API

v1.3.0(10mo ago)1013.3k2[1 issues](https://github.com/salamwaddah/laravel-relation-parser/issues)[1 PRs](https://github.com/salamwaddah/laravel-relation-parser/pulls)MITPHPPHP &gt;=8.1CI passing

Since Jun 28Pushed 9mo ago2 watchersCompare

[ Source](https://github.com/salamwaddah/laravel-relation-parser)[ Packagist](https://packagist.org/packages/salamwaddah/laravel-relation-parser)[ RSS](/packages/salamwaddah-laravel-relation-parser/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (17)Used By (0)

[![Latest Version on Packagist](https://camo.githubusercontent.com/48713d9c5f134cfff0b168d1956fe3c02762f78a490cea993c210302b96f2f80/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73616c616d7761646461682f6c61726176656c2d72656c6174696f6e2d7061727365722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/salamwaddah/laravel-relation-parser)[![Total Downloads](https://camo.githubusercontent.com/595cc86bea0c4ebe3b27bc986618588fe5768a3130099d129c904d02e77dbbf3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73616c616d7761646461682f6c61726176656c2d72656c6174696f6e2d7061727365722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/salamwaddah/laravel-relation-parser)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

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

[](#installation)

```
composer require salamwaddah/laravel-relation-parser
```

VersionLaravelPHP1.x10, 11, 12&gt;= 8.10.3.x8, 9&gt;= 7.3Usage
-----

[](#usage)

Allow your application to load any model relation in the response without the need of changing your API controllers.

Pass a comma separated relations to your http request.

### Loading relations

[](#loading-relations)

Add a `with` param to your HTTP request

`/users?with=orders,posts,anyOtherRelation`

### Loading relation counts

[](#loading-relation-counts)

Add a `with_count` param to your HTTP request

`/users?with_count=orders,anyOtherRelation,anotherRelationToCount,blaBlaBla`

### Loading relations and counts

[](#loading-relations-and-counts)

`/users?with=orders&with_count=orders`

### In your controller

[](#in-your-controller)

```
use SalamWaddah\RelationParser\LoadsRelations;
use Illuminate\Http\Request;

class UsersController extends Controller
{
    use LoadsRelations;

    public function index(Request $request)
    {
            $users = User::query()
                // .. your query logic here
                ->get();

            // this line adds the relations/counts
            $this->loadRelations($users, $request);

            // return your results however you like
            return response()->json($users);
        }
    }
```

Response example
----------------

[](#response-example)

```
[
  {
    "id": 1,
    "name": "Salam",
    "orders_count": 2,
    "orders": [
      {
        "id": 2,
        "product": "something",
        "price": 100
      },
      {
        "id": 1,
        "product": "something else",
        "price": 150
      }
    ]
  },
  {
    "id": 2,
    "name": "Naren",
    "orders_count": 1,
    "orders": [
      {
        "id": 3,
        "product": "something",
        "price": 100
      }
    ]
  }
]
```

Customize
---------

[](#customize)

If `with` or `with_count` params are used for something else in your application then you can customize those params in `loadRelations()` method.

> $this-&gt;loadRelations($users, $request, 'customWithParam', 'custom\_with\_count\_param');

Testing
-------

[](#testing)

```
composer test
```

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance53

Moderate activity, may be stable

Popularity30

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity68

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 ~97 days

Recently: every ~216 days

Total

16

Last Release

315d ago

Major Versions

0.3.1 → 1.0.02023-05-07

PHP version history (2 changes)0.0.1PHP &gt;=7.3

1.0.0PHP &gt;=8.1

### Community

Maintainers

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

---

Top Contributors

[![salamwaddah](https://avatars.githubusercontent.com/u/26627088?v=4)](https://github.com/salamwaddah "salamwaddah (53 commits)")

---

Tags

eloquenteloquent-modelseloquent-ormjsonlaravelrelationslaravelmodel relationsrelation loader

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/salamwaddah-laravel-relation-parser/health.svg)

```
[![Health](https://phpackages.com/badges/salamwaddah-laravel-relation-parser/health.svg)](https://phpackages.com/packages/salamwaddah-laravel-relation-parser)
```

###  Alternatives

[ntanduy/cloudflare-d1-database

Easy configuration and setup for D1 Database connections in Laravel.

215.4k](/packages/ntanduy-cloudflare-d1-database)

PHPackages © 2026

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