PHPackages                             ehsan-coder/resource-methods - 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. ehsan-coder/resource-methods

ActiveLibrary[API Development](/categories/api)

ehsan-coder/resource-methods
============================

this package added new methods to modified your api resource, such as you can use only or except methods to customize your api resources when use in controllers.

v1.0.0(2y ago)14MITPHPPHP ^7.2|^8.0

Since Jun 6Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ehsan-coder/resource-methods)[ Packagist](https://packagist.org/packages/ehsan-coder/resource-methods)[ RSS](/packages/ehsan-coder-resource-methods/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

[![Logo](https://camo.githubusercontent.com/b48c6febe668fa055510f5ff0c433a997a53881f66766dd86ede184500a1d8fe/68747470733a2f2f73382e7575706c6f61642e69722f66696c65732f65685f68317a302e6a7067)](https://camo.githubusercontent.com/b48c6febe668fa055510f5ff0c433a997a53881f66766dd86ede184500a1d8fe/68747470733a2f2f73382e7575706c6f61642e69722f66696c65732f65685f68317a302e6a7067)

Eloquent API Resource Methods
=============================

[](#eloquent-api-resource-methods)

API Resources in laravel is very common, If you are here, you most likely know about and use them. API Resources is very useful, but it lacks a bit of the "Laravel way" when you want use methods such as except or only, because you may want to modified output of the Resource. by this package you can do this!

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

[](#installation)

You can install the package via composer:

```
 composer require ehsan-coder/resource-methods
```

Usage/Examples
--------------

[](#usageexamples)

On any API Resource you want to be able to use the methods described below, you should use the following trait:

```
use EhsanCoder\ResourceMethods;

class UserResource extends JsonResource
{
    use ResourceMethodsTrait;
}
```

This package provides a few features.

#### Only method

[](#only-method)

if your resource have a toArrray method like this, you can use only method such as below:

```
    public function toArray($request)
    {
        $response = [
            'id'              => $this->id,
            'username'        => $this->username,
            'status'          => $this->status,
            'name'            => $this->name,
        ];
        return $response;
    }
```

```
    $user                 = \App\Models\User::query()->first();
    $userThatHaveOnlyName = \App\Http\Resources\UserResource::make($user)->only('name');
```

in this method, if you want use multi property for apply only method you can use such as below:

```
    $user                      = \App\Models\User::query()->first();
    $userThatHaveOnlyNameAndId = \App\Http\Resources\UserResource::make($user)->only(['id','name']);
```

#### Except method

[](#except-method)

if your resource have a toArrray method like this, you can use except method such as below:

```
    public function toArray($request)
    {
        $response = [
            'id'              => $this->id,
            'username'        => $this->username,
            'status'          => $this->status,
            'name'            => $this->name,
        ];
        return $response;
    }
```

```
    $user                 = \App\Models\User::query()->first();
    $userThatHaveAllPropertiesExceptName = \App\Http\Resources\UserResource::make($user)->except('name');
```

in this method, if you want use multi property for apply except method you can use such as below:

```
    $user                      = \App\Models\User::query()->first();
    $userThatHaveAllPropertiesExceptNameAndId = \App\Http\Resources\UserResource::make($user)->except(['id','name']);
```

in except method, you can do a magical work! if you have a nested json, In other words you have a property with value json you can except any key-value into this json value, for examaple:

```
    $device                      = \App\Models\Devices::query()->first();
    $deviceThatExceptSomeKeyValuesInModelJsonProperty = \App\Http\Resources\DeviceResource::make($device)->except(['model->name', 'model->brand->country'])
```

#### overwrite method

[](#overwrite-method)

in this method you can modified any value of any output resource propery.for example:

```
    $user                          = \App\Models\User::query()->first();
    $camelCaseNameValueForThisUser = \App\Http\Resources\UserResource::make($user)->overwrite('name', fn(string $name) => camel_case($name));
```

Feedback
--------

[](#feedback)

If you have any feedback, please reach out to us at

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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

Unknown

Total

1

Last Release

1077d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e33c60e75be155de4b37b0ba04642de57bd71bb33b0ba13a5427093bfe12b966?d=identicon)[ehsan-coder](/maintainers/ehsan-coder)

---

Top Contributors

[![ehsan-coder](https://avatars.githubusercontent.com/u/52177938?v=4)](https://github.com/ehsan-coder "ehsan-coder (3 commits)")

---

Tags

laravelresourcelaravel-resourceresource API

### Embed Badge

![Health badge](/badges/ehsan-coder-resource-methods/health.svg)

```
[![Health](https://phpackages.com/badges/ehsan-coder-resource-methods/health.svg)](https://phpackages.com/packages/ehsan-coder-resource-methods)
```

###  Alternatives

[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

2.9k34.0M112](/packages/darkaonline-l5-swagger)[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k7.6M74](/packages/openai-php-laravel)[knuckleswtf/scribe

Generate API documentation for humans from your Laravel codebase.✍

2.3k12.2M45](/packages/knuckleswtf-scribe)[joskolenberg/laravel-jory

Create a flexible API for your Laravel application using json based queries.

4513.5k](/packages/joskolenberg-laravel-jory)[vemcogroup/laravel-weather

Weather package for Laravel to use different providers to get weather info

5525.0k](/packages/vemcogroup-laravel-weather)[scriptdevelop/whatsapp-manager

Paquete para manejo de WhatsApp Business API en Laravel

762.6k](/packages/scriptdevelop-whatsapp-manager)

PHPackages © 2026

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