PHPackages                             engency/resource-controllers - 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. engency/resource-controllers

ActiveLibrary[Framework](/categories/framework)

engency/resource-controllers
============================

Resource Controllers for Laravel

v0.5.5(2y ago)22.1k[1 issues](https://github.com/Engency/laravel-resource-controller/issues)[3 PRs](https://github.com/Engency/laravel-resource-controller/pulls)MITPHPPHP ^7.4|^8.0

Since Oct 19Pushed 5d ago1 watchersCompare

[ Source](https://github.com/Engency/laravel-resource-controller)[ Packagist](https://packagist.org/packages/engency/resource-controllers)[ RSS](/packages/engency-resource-controllers/feed)WikiDiscussions develop Synced yesterday

READMEChangelog (8)Dependencies (8)Versions (18)Used By (0)

Laravel Resources
=================

[](#laravel-resources)

[![](https://camo.githubusercontent.com/0c94a7611b128eebfe6dc7c76d4d39df023097e49031e9a5782d803beff53f0b/68747470733a2f2f636972636c6563692e636f6d2f67682f456e67656e63792f6c61726176656c2d7265736f757263652d636f6e74726f6c6c65722e7376673f7374796c653d736869656c64)](https://app.circleci.com/pipelines/github/Engency/laravel-resource-controller)

Don't waste valuable time on writing basic CRUD operations for your Laravel application.

### Ideology

[](#ideology)

Most CRUD operations are very straight-forward, especially when conforming to the [REST design](https://en.wikipedia.org/wiki/Representational_state_transfer). As long as a few basic rules are met, generic logic can do the trick.

1. Middleware authorizes users for operations on resources
2. The controller determines the scope
3. Rules validate input before storing and updating resources
4. Rules make sure clients will only receive the attributes they are authorized to see

For applications with both an API and 'general' webinterface, you ideally just want a single controller performing the basic crud operations on a resource. Therefore, generic logic should be able to construct responses in both HTML and JSON format.

Requirements
------------

[](#requirements)

- PHP 7.1+ | PHP 8+
- The Laravel framework

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

[](#installation)

```
composer require engency/laravel-resource-controller
```

*Alongside this package, the [engency/eloquent-formatting](https://github.com/Engency/eloquent-formatting) and [engency/laravel-model-validation](https://github.com/Engency/laravel-model-validation) package will be installed.*

Usage
-----

[](#usage)

The most basic setup could look as following;

*The controller*

```
use Illuminate\Http\Request;
use Engency\Http\Controllers\ResourceController;
use Engency\Http\Controllers\DefaultResourceActions;

class UserController extends ResourceController
{
    use DefaultResourceActions;

    /**
     * Provide the resource class in the parent's constructor.
     * Add any middleware to authorize users.
     */
    public function __construct()
    {
        parent::__construct(User::class);

        $this->middelware('auth');
    }

    /**
     * Set the scope for this resource controller.
     * The expected return value should either be a query builder or a Laravel collection.
     *
     * @param Request $request
     * @return \Illuminate\Database\Query\Builder|\Illuminate\Support\Collection|\Illuminate\Database\Query\Builder
     */
    protected function getScope(Request $request)
    {
        return User::query();
    }

}
```

*The model*

```
use \Illuminate\Database\Eloquent\Model;
use \Engency\ModelValidation\Validatable;
use Engency\DataStructures\CustomDataFormats;
use Engency\DataStructures\ExportsCustomDataFormats;

class User extends Model implements ExportsCustomDataFormats
{
    use Validatable; // trait required for laravel-model-validation
    use CustomDataFormats; // trait required for eloquent-formatting

    protected $fillable = [
        'name',
        'email'
    ];

    /**
     * Make sure clients only receive data they are authorized for.
     * Visit complete documentation on custom export formats on;
     * https://github.com/Engency/eloquent-formatting
     */
    protected $exports = [
        'default' => [
            'name',
        ],
        'complete' => [
            'name',
            'email'
        ]
    ];

    /**
     * Basic validation for resource attributes.
     * Visit complete documentation on model validation on;
     * https://github.com/Engency/laravel-model-validation
     */
    public function rules() : array {
        return [
            'name' => 'required|string',
            'email' => 'required|email'
        ];
    }

}
```

### Html response

[](#html-response)

The controller will find for the following views;

- *resource-path*/views/pages/*resource-name-kebab-case*/**index**.blade.php
- *resource-path*/views/pages/*resource-name-kebab-case*/**create**.blade.php
- *resource-path*/views/pages/*resource-name-kebab-case*/**show**.blade.php
- *resource-path*/views/pages/*resource-name-kebab-case*/**edit**.blade.php

Within the index.blade.php file, the $items variable will be present by default. The index.blade.php file could look as following;

```

@foreach($items as $item)
    {{ $item->name }}
@endforeach

```

Any page showing a resource (show and edit) have access to the resource. The name of the variable is the name of the resource, in camel case. E.g., 'StreetSign' would be '$streetSign'. The show.blade.php file could look like this;

```
You are viewing {{ $user->name }}.
The corresponding email address is {{ $user->email }}.
```

In addition to that, the controller uses specific error pages;

- *resource-path*/views/pages/error/**unauthorized**.blade.php
- *resource-path*/views/pages/error/**notfound**.blade.php
- *resource-path*/views/pages/error/**conflict**.blade.php
- *resource-path*/views/pages/error/**forbidden**.blade.php
- *resource-path*/views/pages/error/**500**.blade.php

### JSON response

[](#json-response)

*Response for the index call*

```
{
  "items": [
      {"name": "John"},
      {"name": "Doe"}
  ]
}
```

Contributors
------------

[](#contributors)

- Frank Kuipers ([GitHub](https://github.com/frankkuipers))
- Feel free to contribute or submit feature-requests as issues.

License
-------

[](#license)

This plugin is licenced under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance55

Moderate activity, may be stable

Popularity20

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 60.7% 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 ~152 days

Recently: every ~255 days

Total

10

Last Release

757d ago

PHP version history (2 changes)v0.1PHP ^7.4

v0.3PHP ^7.4|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1830445?v=4)[Frank Kuipers](/maintainers/frankkuipers)[@frankkuipers](https://github.com/frankkuipers)

---

Top Contributors

[![renovate[bot]](https://avatars.githubusercontent.com/in/2740?v=4)](https://github.com/renovate[bot] "renovate[bot] (119 commits)")[![renovate-bot](https://avatars.githubusercontent.com/u/25180681?v=4)](https://github.com/renovate-bot "renovate-bot (48 commits)")[![frankkuipers](https://avatars.githubusercontent.com/u/1830445?v=4)](https://github.com/frankkuipers "frankkuipers (29 commits)")

---

Tags

laravelresourcecontroller

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/engency-resource-controllers/health.svg)

```
[![Health](https://phpackages.com/badges/engency-resource-controllers/health.svg)](https://phpackages.com/packages/engency-resource-controllers)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.6k31.8M162](/packages/laravel-cashier)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k16.3M154](/packages/laravel-pulse)[api-platform/laravel

API Platform support for Laravel

58190.1k21](/packages/api-platform-laravel)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9922.4M146](/packages/roots-acorn)[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

79227.1M229](/packages/laravel-mcp)

PHPackages © 2026

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