PHPackages                             binarcode/laravel-restable - 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. binarcode/laravel-restable

ActiveLibrary

binarcode/laravel-restable
==========================

Lightweight Laravel API.

1.0.0(4y ago)11.1k1MITPHPPHP ^8.0

Since Apr 3Pushed 4y ago2 watchersCompare

[ Source](https://github.com/BinarCode/laravel-restable)[ Packagist](https://packagist.org/packages/binarcode/laravel-restable)[ Docs](https://github.com/binarcode/laravel-restable)[ GitHub Sponsors](https://github.com/BinarCode)[ RSS](/packages/binarcode-laravel-restable/feed)WikiDiscussions master Synced 1w ago

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

Laravel Restable
================

[](#laravel-restable)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c8f71c14eb98084d77b5318593f6d97ee118b0f95c4bd3f0c89d0b049bf15c00/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62696e6172636f64652f6c61726176656c2d7265737461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/binarcode/laravel-restable)[![GitHub Tests Action Status](https://camo.githubusercontent.com/ee37f919cdc0840e7a8423e24c1913f2297fcef2b3767616b2cc13deb159ccea/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f62696e6172636f64652f6c61726176656c2d7265737461626c652f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/binarcode/laravel-restable/actions?query=workflow%3ATests+branch%3Amaster)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/6e853c2145a98a85ba3abb3be7d8456eafc3498942e26e0a4b0a7aa62cd691c1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f62696e6172636f64652f6c61726176656c2d7265737461626c652f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/binarcode/laravel-restable/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/50bcb92d87537b2ee6d47cddb5cbee01642bdefa78760450798b72a647dec91d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f62696e6172636f64652f6c61726176656c2d7265737461626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/binarcode/laravel-restable)

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

[](#installation)

You can install the package via composer:

```
composer require binarcode/laravel-restable
```

Prerequisite
------------

[](#prerequisite)

To associate search with a model, the model must implement the following interface and trait:

```
namespace App\Models;

use BinarCode\LaravelRestable\HasRestable;
use BinarCode\LaravelRestable\Restable;
use Illuminate\Database\Eloquent\Model;

class YourModel extends Model implements Restable
{
    use HasRestable;
}
```

Usage
-----

[](#usage)

Using this lightweight package you can mainly customize `search`, `matches` and `sorts`.

### Search

[](#search)

Define columns you want to be searchable using `$search` model property:

```
class Dream extends Model implements Restable
{
    use HasRestable;

    public static array $search = [
        'name',
    ];
}
```

Now in the query of your request you can use the `?search=` to find over your model. Let's assume this is the URL for geting the list of `dreams`:

```
GET: /api/dreams?search=be happy
```

Then in the controller you may have something like this:

```
use App\Models\Dream;
use Illuminate\Http\Request;

class DreamController extends Controller
{
    public function index(Request $request)
    {
        $dreams = Dream::search($request);

        return response()->json($dreams->paginate());
    }
}
```

This way Restable will find your `dreams` by `name` column and will return a `Builder` instance, so you can `paginate`or do whatever you want over that query.

The query filtering is something like this: `$query->where('column_name', 'like', "%$value%"`;

Match
-----

[](#match)

Matching by a specific column is a more strict type of search. You should define the columns you want to match along with the type:

```
use BinarCode\LaravelRestable\Types;

class Dream extends Model implements Restable
{
    use HasRestable;

    public static array $match = [
        'id' => Types::MATCH_ARRAY,
        'name' => Types::MATCH_TEXT,
    ];
}
```

The URL may look like this:

```
GET: /api/dreams?id=1,2,3&name=happy
```

So Restable will make a query like this:

```
$query->whereIn('id', [1, 2, 3])->where('name','=', 'happy');
```

The controller could be same as we had for the search.

### Sort

[](#sort)

You can also specify what columns could be sortable:

```
class Dream extends Model implements Restable
{
    use HasRestable;

    public static array $sort = [
        'id',
        'name',
    ];
}
```

The query params for sort could indicate whatever is `asc` or `desc` sorting by using the `-` sign:

Sorting `desc` by `id` column:

```
GET: /api/dreams?sort=-id
```

Sorting `asc` by `id` column:

```
GET: /api/dreams?sort=id
```

Customizations
--------------

[](#customizations)

### Model Methods

[](#model-methods)

You can use methods to return your `search`, `matches` or `sorts` from the model definition:

```
class Dream extends Model implements Restable
{
    use HasRestable;

    public static function sorts(): array
    {
        return [ 'id', 'name' ];
    }

    public static function matches(): array
    {
        return [
            'id' => 'int',
            'name' => 'string',
        ];
    }

    public static function searchables(): array
    {
        return ['name'];
    }
}
```

### Custom filters

[](#custom-filters)

Instead of using the default methods for filtering, you can have your own:

```
use BinarCode\LaravelRestable\Filters\MatchFilter;class Dream extends Model implements Restable
{
    use HasRestable;

    public static function matches(): array
    {
        return [
            'something' => MatchFilter::make()->resolveUsing(function($request, $query) {
                   // filter it here
            }),
            'name' => 'string'
        ];
    }
}
```

So you can now match by `something` property, and implement your own search into the closure.

You can also create your own `Match` filter class, and implement the search there:

```
use BinarCode\LaravelRestable\Filters\MatchFilter;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;

class MatchSomething extends MatchFilter
{
        public function apply(Request $request, Builder $query, $value): Builder
        {
            // your filters
            return $query->where('a', $value);
        }

}
```

Then use your `MatchSomething` filter:

```
class Dream extends Model implements Restable
{
    use HasRestable;

    public static function matches(): array
    {
        return [
            'something' => MatchSomething::make(),
            'name' => 'string'
        ];
    }
}
```

The same you could do for `Search` or `Sort` filter, by extending the `BinarCode\LaravelRestable\Filters\SearchableFilter` or `BinarCode\LaravelRestable\Filters\SortableFilter` filters.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Eduard Lupacescu](https://github.com/BinarCode)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

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

Total

2

Last Release

1557d ago

Major Versions

0.0.1 → 1.0.02022-02-11

### Community

Maintainers

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

---

Top Contributors

[![binaryk](https://avatars.githubusercontent.com/u/6833714?v=4)](https://github.com/binaryk "binaryk (27 commits)")

---

Tags

laravelbinarcodelaravel-restable

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/binarcode-laravel-restable/health.svg)

```
[![Health](https://phpackages.com/badges/binarcode-laravel-restable/health.svg)](https://phpackages.com/packages/binarcode-laravel-restable)
```

###  Alternatives

[slowlyo/owl-admin

基于 laravel、amis 开发的后台框架~

61214.2k26](/packages/slowlyo-owl-admin)[erag/laravel-disposable-email

A Laravel package to detect and block disposable email addresses.

226102.4k](/packages/erag-laravel-disposable-email)[highsolutions/eloquent-sequence

A Laravel package for easy creation and management sequence support for Eloquent models with elastic configuration.

121130.3k](/packages/highsolutions-eloquent-sequence)[glhd/linen

21135.6k](/packages/glhd-linen)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

17221.0k3](/packages/interaction-design-foundation-laravel-geoip)

PHPackages © 2026

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