PHPackages                             mapi/easyapi - 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. mapi/easyapi

ActiveLibrary[API Development](/categories/api)

mapi/easyapi
============

This package makes building an API an easy job.

v1.1.6(2y ago)0931↓50%MITPHPPHP &gt;=7.0

Since Nov 4Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Modar-Nahhas/easy-api)[ Packagist](https://packagist.org/packages/mapi/easyapi)[ RSS](/packages/mapi-easyapi/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (8)Dependencies (1)Versions (13)Used By (0)

easy-api
========

[](#easy-api)

This package provides an easy way to build REST Apis providing the basic functionalities in a controlled yet somehow dynamic way.

### These basic functionalities are:

[](#these-basic-functionalities-are)

1. Pagination.
2. Sorting.
3. Searching.
4. Filtering based on columns.

Installation
============

[](#installation)

composer require mapi/easyapi

How it works
============

[](#how-it-works)

This package depends on inheritance and traits to add scopes to the Eloquent model. These scopes provide the basic functionalities mentioned before. It also provides a form request to make it easier to use these functionalities.

Description of the models provided
==================================

[](#description-of-the-models-provided)

1. To use it in an eloquent model, a model should inherit from one of these classes:
    - `ApiModel`: this class is used for models that should extend the `Illuminate\Database\Eloquent\Model` class.
    - ApiPivot: this class is used for models that should extend the `Illuminate\Database\Eloquent\Relations\Pivot`class.
    - `ApiUser`: this is used for a user classes that should extend the `Illuminate\Foundation\Auth\User`.
2. If your class is already inheriting from another class you should use the provided trait:
    - `IsApiModel`: this trait provides the same functionalities as the previous models, but it requires a special treatment to control the behavior of the model.
3. This step is optional and depends on your application. We provide a base form request `BaseRequest`in which we define the validation rules for pagination, sorting, and searching.

How to use
==========

[](#how-to-use)

We will be showing examples on how to implement each functionality in our code.

### Pagination

[](#pagination)

We have implemented this functionality in a scope called `getData`. This scope uses the `paginate` function provided by Laravel framework. It also allows to retrieve all data and minified version of the data.
`PS: The page number should be passed with the request with key name page`

1. Get paginated data
    This can be done by passing an associative array of data which contains a key `number` and its value represents how many records you want ro retrieve per page.
2. Get all data
    To get all data you should send the number parameter in the request with value equal to -1 `number = -1`.
3. Get minified data This functionality allows the developer to control which fields should be retrieved by the model. In some cases, like populating a dropdown list, you probably need two fields. One to represent the value `id` for example and the second to represent the text displayed to the user: `name` for example. to achieve this functionality, there are two steps:
    First override the property `$listColumnsToRetrieve` in the model. Its value should be an array of columns names that should be retrieved if the functionality is called.
    Second to tell the scope to load a minified version of the result, you should send in the data array passed to the scope a key called `list` with value `true`.

```

// Inside your model (MyModel)
class MyModel extends ApiModel {

   protected $listColumnsToRetrieve = [
      'id','name'
   ];

}

// Where you need to retrieve the data (in controller for example)
$data = [
   'list' => 1,
   'number' => 10
];
MyModel::query()->getData($data);`

```

### Sorting

[](#sorting)

We have implemented this functionality in a scope called `sort`. This scope uses the `orderBy` and the `orderByDesc` functions provided by Laravel framework. For now, sorting support sorting on one column. By default, the user is allowed to sort based on all columns. In order to limit the columns allowed to sort by, you can declare a variable called `$allowedColumnsToSortBy`. Its value should be an array of columns' names the user are allowed to sort by. The client can ask to sort the records by sending parameters called `sort` which is a string represents the column name and `sort_desc` which is a boolean represent if the sort direction is descending or not.

```

// Inside your model (MyModel)
class MyModel extends ApiModel {

   protected $allowedColumnsToSortBy = [
      'id','name'
   ];

}

// Where you need to sort the data (in controller for example)
$data = [
   'sort' => 'column_name',
   'sort_desc' => 1
];
MyModel::query()->sort($data);`

```

### Searching

[](#searching)

We have implemented this functionality in a scope called `search`. This scope uses the `where like` to search specific columns in the direct columns of the model or relation columns. By default, the search is not allowed for any column. In order to activate this functionality on `direct columns`, you need to define a variable in the model called `$allowedColumnsToSearch`. Its value should be an array of columns' names that the search process will be applied on. In order to activate this functionality on `relation columns`, you need to define a variable in the model called `$allowedRelationsToSearch`. Its value is an associative array. The `key` represents the `name of the relation` and the `value` is an array of columns' names that the code should search in the respective table. The client can use the search functionality by sending a parameter called `search` and the system will automatically search the direct columns and relations columns defined in the model

```

// Inside your model (MyModel)
class MyModel extends ApiModel {

   protected $allowedColumnsToSearch = [
      'id','name
   ];

   protected $allowedRelationsToSearch = [
      'relation_name_1' => [ 'id','name' ],
      'relation_name_2' => [ 'name','price' ]
   ];

}

// Where you need to sort the data (in controller for example)
$data = [
   'search' => 'search string',
];
MyModel::query()->search($data);`

```

### Filtering

[](#filtering)

We have implemented this functionality in a scope called filter. This scope support different types of filtering. Supported types are:

#### Direct filter types

[](#direct-filter-types)

- where\_.
- or\_where\_.
- whereIn\_.
- whereNotIn\_.
- whereLike\_.
- or\_whereLike\_.
- whereNull\_.
- whereNotNull\_.
- or\_whereNull\_.
- or\_whereNotNull\_.

#### Relation filter types

[](#relation-filter-types)

- where\_relation\_.
- or\_where\_relation\_.
- whereIn\_relation\_.
- whereNotIn\_relation\_.
- whereLike\_relation\_.
- or\_whereLike\_relation\_.
- or\_whereNull\_relation\_.
- or\_whereNotNull\_relation\_.
- whereNull\_relation\_.
- whereNotNull\_relation\_.

The filters work on direct columns of the model or relation's columns. In order to activate this functionality on `direct columns` you need to define a variable called `$allowedFilters` in the model. Its value should be an array of columns' names that the client is allowed to filter based on. In order to activate this functionality on `relation columns`, you need to define a variable in the model called `$allowedRelationsFilters`. Its value should ba an associative array. The `key` is the `name of the relation` we need to filter by its value, and the `value` is an array of columns' name the client is allowed to filter by its value. After you define the allowed columns to filter based on, the client can use the filters by sending the column name as parameter `prefixed` by one of the `direct filters types` for direct columns and `relation filters types` for relations' columns.

```

// Inside your model (MyModel)
class MyModel extends ApiModel {

   protected $allowedFilters = [
      'id','name
   ];

   protected $allowedRelationsFilters = [
      'relation_name_1' => [ 'id','name' ],
      'relation_name_2' => [ 'name','price' ]
   ];

}

// Where you need to sort the data (in controller for example)
$data = [
   'where_name' => 'name 1',
   'where_relation_price' => 500
];
MyModel::query()->filter($data);`

```

### Loading relations

[](#loading-relations)

We have implemented this functionality in a scope called `loadRelations`. This scope allow the client to ask the server to load relations without the need to create multiple APIs from the server side. One API can service different use cases of the client. In order to activate this functionality, you should define a variable called `$allowedRelationsToLoad` in the model. Its value should be an associative array. Its `key` represents the relation name. Its `value` should be an array of the `relation's columns we need to load`. You can use `*` to indicate that you want all columns to be loaded.
`PS: when you define a subset of the columns to be loaded, the foreign key column should be one of these values or the relation will be empty`. The client can use this functionality by sending a parameter representing the `relation name`needed to be loaded `prefixed` by `with_` and its value is boolean indicates that the relation is needed or not.

```

// Inside your model (MyModel)
class MyModel extends ApiModel {

   protected $allowedRelationsToLoad = [
      'relation_name_1' => [ 'id','name' ],
      'relation_name_2' => [ 'id','name','price' ]
   ];

}

// Where you need to sort the data (in controller for example)
$data = [
   'with_relation_name_1' => 0,
   'with_relation_name_2' => 1
];
MyModel::query()->loadRelations($data);`

```

### Applying all functionalities

[](#applying-all-functionalities)

If you want all functionalities to be used, you can use the scope `applyAllFilters` and pass the input sent by the client.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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

Recently: every ~163 days

Total

10

Last Release

846d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1740f6f47bee17b0f59002deb29be2e9a0e762b50290670231bb7345b30e3423?d=identicon)[Modar-Nahhas](/maintainers/Modar-Nahhas)

---

Top Contributors

[![Modar-Nahhas](https://avatars.githubusercontent.com/u/58506275?v=4)](https://github.com/Modar-Nahhas "Modar-Nahhas (1 commits)")

### Embed Badge

![Health badge](/badges/mapi-easyapi/health.svg)

```
[![Health](https://phpackages.com/badges/mapi-easyapi/health.svg)](https://phpackages.com/packages/mapi-easyapi)
```

###  Alternatives

[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

2.9k34.0M112](/packages/darkaonline-l5-swagger)[echolabsdev/prism

A powerful Laravel package for integrating Large Language Models (LLMs) into your applications.

2.3k388.3k10](/packages/echolabsdev-prism)[sburina/laravel-whmcs-up

WHMCS API client and user provider for Laravel

271.3k](/packages/sburina-laravel-whmcs-up)

PHPackages © 2026

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