PHPackages                             gblix/laravel-controller-repository-traits - 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. [Framework](/categories/framework)
4. /
5. gblix/laravel-controller-repository-traits

ActiveLibrary[Framework](/categories/framework)

gblix/laravel-controller-repository-traits
==========================================

Traits para Controllers de Laravel facilitando uso da lib `prettus/l5-repository`

1.9.0(1mo ago)18.1kMITPHPPHP ^8.3CI passing

Since Feb 21Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/GBLIX/laravel-controller-repository-traits)[ Packagist](https://packagist.org/packages/gblix/laravel-controller-repository-traits)[ RSS](/packages/gblix-laravel-controller-repository-traits/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (10)Dependencies (27)Versions (21)Used By (0)

gblix/laravel-controller-repository-traits
==========================================

[](#gblixlaravel-controller-repository-traits)

Controller traits for Laravel that streamline building REST APIs on top of [`prettus/l5-repository`](https://github.com/andersao/l5-repository). The package wires controllers, repositories, Fractal presenters and validators together so each CRUD endpoint becomes a one-liner with well-defined customization hooks.

Version compatibility
---------------------

[](#version-compatibility)

Package versionLaravelPHPprettus/l5-repository1.8.x12, 13≥ 8.3`^2.10 || ^4.0`1.7.x (beta)12≥ 8.3`^2.10`1.6.x11≥ 8.3`^2.9.1`> **Laravel 13 requires prettus/l5-repository 4.x** (2.x/3.x cap at `illuminate/* ^12`). On Laravel 12 either prettus major works, which lets you upgrade this package first and migrate to prettus 4.x at your own pace.

### Upgrading with prettus 4.x installed

[](#upgrading-with-prettus-4x-installed)

prettus/l5-repository 4.0 bundles the `Prettus\Validator\*` classes inside the package itself. **Do not require `prettus/laravel-validation` alongside l5-repository 4.x** — both define the same `Prettus\Validator` namespace and composer will report ambiguous class resolution. Remove `prettus/laravel-validation` from your app's `composer.json` when moving to prettus 4.x; no code changes are needed (`Prettus\Validator\LaravelValidator` and friends keep the same API).

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

[](#installation)

```
composer require gblix/laravel-controller-repository-traits
```

Register the macro service provider (not auto-discovered) to enable the `paginateNoLimit`/`paginateAll` Eloquent builder macros:

```
// config/app.php (or bootstrap/providers.php on Laravel 11+)
Gblix\ServiceProviders\EloquentMacroServiceProvider::class,
```

Usage
-----

[](#usage)

### Controller traits

[](#controller-traits)

Six traits under `Gblix\Controllers\ApiTraits` implement the default REST actions. They expect the controller to expose a `$repository` property implementing `Gblix\Repository\Contracts\RepositoryInterface`:

```
use Gblix\Controllers\ApiTraits;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Symfony\Component\HttpFoundation\Response;

class UsersController extends Controller
{
    use ApiTraits\Retrieve;  // index()
    use ApiTraits\Read;      // getCurrentEntryId() + shared read hooks
    use ApiTraits\Show;      // show()
    use ApiTraits\Create;    // runStore() — you implement store()
    use ApiTraits\Update;    // runUpdate() — you implement update()
    use ApiTraits\Delete;    // destroy()

    protected UserRepository $repository;

    public function __construct(UserRepository $repository)
    {
        $this->repository = $repository;
    }

    public function store(Request $request): Response
    {
        return $this->runStore($request, CreateUserAction::class);
    }

    public function update(Request $request): Response
    {
        return $this->runUpdate($request, UpdateUserAction::class);
    }
}
```

`Create`/`Update`/`Delete` dispatch a "job" object: Laravel Actions v2 (`asController()`), Laravel Actions v1 (`actingAs()->run()`) and plain classes with `run()`/`handle(array $data)`are all supported.

#### Index behavior (`Retrieve`)

[](#index-behavior-retrieve)

`index()` paginates by default and honors the `limit` query parameter:

`limit`Result*absent*`paginate()` with the default page size (`repository.pagination.limit`)`0``paginateNoLimit()` — pagination metadata only, empty `data``-1``paginateAll()` — every record plus pagination metadataany other int`paginate(limit)`If the repository's model defines `scopeFilter`, the request input is forwarded to it through `EntityFilterCriteria` (a JSON `filter` query parameter is decoded automatically).

#### Customization hooks

[](#customization-hooks)

HookTraitPurpose`pushIndexCriteria($repository, $request)`RetrieveExtra criteria for `index``pushEntityRelations($repository, $request)`RetrieveEager-load relations`filterRequestToEntityFilter($request, $data)`RetrieveMutate filter data`willIndexPaginate()`RetrieveReturn `false` to disable pagination`getRetrievePresenter()` / `getShowPresenter()` / `getStorePresenter()` / `getUpdatePresenter()`eachPer-action presenter override`pushReadCriteria($repository)`ReadCriteria shared by show/update/delete`pushShowCriteria($repository)` / `pushDestroyCriteria($repository)`Show / DeletePer-action criteria`$routeKey` / `$resource` propertiesReadCustomize how the entry id is read from the route### Repository

[](#repository)

Extend `Gblix\Repository\BaseRepository` (which extends `Prettus\Repository\Eloquent\BaseRepository`):

```
use Gblix\Repository\BaseRepository;

class UserRepository extends BaseRepository
{
    public function model()
    {
        return User::class;
    }

    public function presenter()
    {
        return UserPresenter::class;
    }

    public function validator()
    {
        return UserValidator::class;
    }
}
```

Extras on top of prettus: `exists($id)`, `cursor()`, `paginateNoLimit()`, `paginateAll()` and `collectionPresenter()` (an optional presenter class used for collections).

### Presenter

[](#presenter)

Extend `Gblix\Presenters\FractalPresenter` and return a [league/fractal](https://fractal.thephpleague.com/) transformer:

```
use Gblix\Presenters\FractalPresenter;
use League\Fractal\TransformerAbstract;

class UserPresenter extends FractalPresenter
{
    public function getTransformer(): TransformerAbstract
    {
        return new UserTransformer();
    }
}
```

### Validator

[](#validator)

Extend `Gblix\Validators\BaseValidator` (a `Prettus\Validator\LaravelValidator`). `passesOrFail()` throws Laravel's own `Illuminate\Validation\ValidationException`, so failures render as standard 422 responses:

```
use Gblix\Validators\BaseValidator;
use Prettus\Validator\Contracts\ValidatorInterface;

class UserValidator extends BaseValidator
{
    protected $rules = [
        ValidatorInterface::RULE_CREATE => ['name' => 'required'],
        ValidatorInterface::RULE_UPDATE => ['name' => 'sometimes|required'],
    ];
}
```

### Entity filter criteria

[](#entity-filter-criteria)

`Gblix\Repositories\Criteria\EntityFilterCriteria` forwards an array to the model's `scopeFilter`:

```
public function scopeFilter(Builder $query, ?array $data): Builder
{
    if (isset($data['name'])) {
        $query->where('name', 'like', "%{$data['name']}%");
    }

    return $query;
}
```

Testing
-------

[](#testing)

All tests run inside Docker — nothing is executed on the host machine. One command runs every supported combination (CI uses the same script):

```
./scripts/test-all.sh
```

MatrixPHPLaravelprettus/l5-repository`test-l13`8.4134.x`test-l12`8.3124.x`test-l12-prettus2`8.3122.xIndividual matrices can be run with `docker compose run --rm `. The non-canonical matrices use isolated `composer-.json`/`.lock`/`vendor-/` artifacts (gitignored) so they never clobber the committed lock file.

Releasing
---------

[](#releasing)

1. Merge to `master` via pull request (CI runs both matrices).
2. Tag the release (`git tag 1.8.0 && git push origin 1.8.0`).
3. The `Release` workflow re-runs the matrices and creates the GitHub Release; Packagist syncs automatically.

###  Health Score

55

—

FairBetter than 97% of packages

Maintenance90

Actively maintained with recent releases

Popularity25

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 60% 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 ~151 days

Recently: every ~113 days

Total

14

Last Release

36d ago

PHP version history (3 changes)1.3.0PHP ^7.3 || ^8

1.4.4PHP ^8.1

1.6.0PHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5975514?v=4)[Gustavo Brigo](/maintainers/gustavobrigo)[@gustavobrigo](https://github.com/gustavobrigo)

---

Top Contributors

[![stephandesouza](https://avatars.githubusercontent.com/u/159077?v=4)](https://github.com/stephandesouza "stephandesouza (12 commits)")[![gustavobrigo](https://avatars.githubusercontent.com/u/5975514?v=4)](https://github.com/gustavobrigo "gustavobrigo (4 commits)")[![wederfabricio](https://avatars.githubusercontent.com/u/30693378?v=4)](https://github.com/wederfabricio "wederfabricio (3 commits)")[![flaviolopesw](https://avatars.githubusercontent.com/u/88406106?v=4)](https://github.com/flaviolopesw "flaviolopesw (1 commits)")

###  Code Quality

Static AnalysisPHPStan, Psalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/gblix-laravel-controller-repository-traits/health.svg)

```
[![Health](https://phpackages.com/badges/gblix-laravel-controller-repository-traits/health.svg)](https://phpackages.com/packages/gblix-laravel-controller-repository-traits)
```

###  Alternatives

[bagisto/bagisto

Bagisto Laravel E-Commerce

28.0k175.2k9](/packages/bagisto-bagisto)[unopim/unopim

UnoPim Laravel PIM

10.8k2.5k](/packages/unopim-unopim)[krayin/laravel-crm

Krayin CRM

23.6k33.9k1](/packages/krayin-laravel-crm)[getgrav/grav

Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS

15.6k88.1k1](/packages/getgrav-grav)[mehrancodes/laravel-harbor

A CLI tool to Quickly create On-Demand preview environment for your apps.

99100.2k](/packages/mehrancodes-laravel-harbor)[lavalite/framework

The lavalite framework

5861.7k1](/packages/lavalite-framework)

PHPackages © 2026

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