PHPackages                             hellomohsinhello/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. [API Development](/categories/api)
4. /
5. hellomohsinhello/laravel-relation-parser

ActiveLibrary[API Development](/categories/api)

hellomohsinhello/laravel-relation-parser
========================================

Easily load model relations from frontend without changing your API

1.0.2(1y ago)0299—0%MITPHPPHP &gt;=8.2

Since Mar 6Pushed 1y agoCompare

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

READMEChangelog (3)Dependencies (4)Versions (6)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&gt;= 8.10.3.x8, 9, 10&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

33

—

LowBetter than 75% of packages

Maintenance44

Moderate activity, may be stable

Popularity15

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 86.7% 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 ~0 days

Total

5

Last Release

438d ago

Major Versions

0.1.0 → 1.0.02025-03-06

### Community

Maintainers

![](https://www.gravatar.com/avatar/1b02779f8ac2b82863e4874d4cfbe7d7bee8e9885a16aa5a672aa7c58f7ca4ed?d=identicon)[hellomohsinhello](/maintainers/hellomohsinhello)

---

Top Contributors

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

---

Tags

laravelmodel relationsrelation loader

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[essa/api-tool-kit

set of tools to build an api with laravel

52680.5k](/packages/essa-api-tool-kit)[flat3/lodata

OData v4.01 Producer for Laravel

96320.9k](/packages/flat3-lodata)[ryangjchandler/bearer

Minimalistic token-based authentication for Laravel API endpoints.

8129.8k](/packages/ryangjchandler-bearer)[simplestats-io/laravel-client

Client for SimpleStats!

4515.5k](/packages/simplestats-io-laravel-client)[salamwaddah/laravel-relation-parser

Easily load model relations from frontend without changing your API

1013.3k](/packages/salamwaddah-laravel-relation-parser)[surface/laravel-webfinger

A Laravel package to create an ActivityPub webfinger.

113.8k](/packages/surface-laravel-webfinger)

PHPackages © 2026

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