PHPackages                             mohamed-ibrahem/advanced-json-resource - 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. mohamed-ibrahem/advanced-json-resource

ActiveLibrary[API Development](/categories/api)

mohamed-ibrahem/advanced-json-resource
======================================

Advanced JSON laravel resources

v0.9.0(3y ago)017PHPPHP ^7.3|^8.0

Since Mar 7Pushed 3y ago1 watchersCompare

[ Source](https://github.com/mohamed-ibrahem/advanced-json-resource)[ Packagist](https://packagist.org/packages/mohamed-ibrahem/advanced-json-resource)[ RSS](/packages/mohamed-ibrahem-advanced-json-resource/feed)WikiDiscussions main Synced 1mo ago

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

Very short description of the package
=====================================

[](#very-short-description-of-the-package)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8f52126b666f3dce0dc8a62975c277418cb31ad1290ff145a80d2aedd338894e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6f68616d65642d6962726168656d2f616476616e6365642d6a736f6e2d7265736f757263652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mohamed-ibrahem/advanced-json-resource)[![Total Downloads](https://camo.githubusercontent.com/837dfe10590ed4cc2bec1c716b8c611c6fec352ddfe3f5c3e2aaacf808fe0046/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6f68616d65642d6962726168656d2f616476616e6365642d6a736f6e2d7265736f757263652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mohamed-ibrahem/advanced-json-resource)[![run-tests](https://github.com/mohamed-ibrahem/advanced-json-resource/actions/workflows/run-tests.yml/badge.svg)](https://github.com/mohamed-ibrahem/advanced-json-resource/actions/workflows/run-tests.yml)

Create an advanced json responses for your Laravel application by creating a method for every response type, For example `toIndex`, `toShow`, `toForm`, or a custom method name! Also you have `shared` method for all shared attributes.

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

[](#installation)

You can install the package via composer:

```
composer require mohamed-ibrahem/advanced-json-resource
```

### Usage

[](#usage)

Every resource should extends the `AdvancedJsonResponse\ApiResource` class.

Now based on your response type you can create the methods. And in the controller call these methods in snake case without `to` in the beginning.

### Example

[](#example)

```
use AdvancedJsonResource\ApiResource;
use App\Models\User;
use Illuminate\Http\Request;

/**
 * @mixin User
 */
class UserResource extends ApiResource
{
    /**
     * {@inheritdoc}
     *
     * @param Request $request
     * @return array
     */
    public function toIndex(Request $request): array
    {
        return [
            'name' => $this->name,
        ];
    }

    /**
     * {@inheritdoc}
     *
     * @param Request $request
     * @return array
     */
    public function toShow(Request $request): array
    {
        return [
            'email' => $this->email,
        ];
    }

    /**
     * {@inheritdoc}
     *
     * @param Request $request
     * @return array
     */
    public function toForm(Request $request): array
    {
        return [
            'can_update' => true,
        ];
    }

    /**
     * This is a custom response method.
     *
     * @param Request $request
     * @return array
     */
    public function toCustom(Request $request): array
    {
        return [
            'custom' => 'custom',
        ];
    }

    /**
     * {@inheritdoc}
     *
     * @param Request $request
     * @return array
     */
    public function shared(Request $request): array
    {
        return [
            'id' => $this->id,
        ];
    }
}
```

In the controller:

```
use App\Models\User;
use App\Http\Resources\UserResource;
use Illuminate\Http\Request;

class UserController
{
    public function index(): UserResource
    {
        return UserResource::index(
            User::all(),
        );
    }

    public function store(Request $request): UserResource
    {
        //...

        return UserResource::form($user);
    }

    public function show(User $user): UserResource
    {
        return UserResource::show($user);
    }

    public function custom(Request $request, User $user): UserResource
    {
        return UserResource::cutsom($user);
    }
}
```

### Testing

[](#testing)

```
composer test
```

Credits
-------

[](#credits)

- [Mohamed Ibrahim](https://github.com/mohamed-ibrahim)
- [All Contributors](../../contributors)

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

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

Total

2

Last Release

1161d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/253e0dcfb7f485c6b8abe78b3f1b72b7c3f032f5c78d5b2f769cef597ff4b2f5?d=identicon)[mohamed-ibrahem](/maintainers/mohamed-ibrahem)

---

Top Contributors

[![mohamed-ibrahem](https://avatars.githubusercontent.com/u/20428315?v=4)](https://github.com/mohamed-ibrahem "mohamed-ibrahem (39 commits)")

---

Tags

apilaravel

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mohamed-ibrahem-advanced-json-resource/health.svg)

```
[![Health](https://phpackages.com/badges/mohamed-ibrahem-advanced-json-resource/health.svg)](https://phpackages.com/packages/mohamed-ibrahem-advanced-json-resource)
```

###  Alternatives

[mollie/laravel-mollie

Mollie API client wrapper for Laravel &amp; Mollie Connect provider for Laravel Socialite

3624.1M28](/packages/mollie-laravel-mollie)[mll-lab/laravel-graphiql

Easily integrate GraphiQL into your Laravel project

683.2M9](/packages/mll-lab-laravel-graphiql)[spatie/laravel-route-discovery

Auto register routes using PHP attributes

23645.0k2](/packages/spatie-laravel-route-discovery)[esign/laravel-conversions-api

A laravel wrapper package around the Facebook Conversions API

69145.4k](/packages/esign-laravel-conversions-api)[didww/didww-api-3-php-sdk

PHP SDK for DIDWW API 3

1218.2k](/packages/didww-didww-api-3-php-sdk)[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)
