PHPackages                             mixerapi/crud - 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. [Admin Panels](/categories/admin)
4. /
5. mixerapi/crud

ActiveCakephp-plugin[Admin Panels](/categories/admin)

mixerapi/crud
=============

A CRUD (Create, Read, Update, Delete) plugin for your CakePHP project.

v2.0.7(3mo ago)19.7k↓30%MITPHPPHP ^8.1

Since Jul 7Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/mixerapi/crud)[ Packagist](https://packagist.org/packages/mixerapi/crud)[ RSS](/packages/mixerapi-crud/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (8)Versions (19)Used By (0)

MixerApi CRUD
=============

[](#mixerapi-crud)

!\[Stability\]\[ico-stability\]

[![Version](https://camo.githubusercontent.com/046937cf63137a52ad9bf34da0477aec9fbfbd5d1fe72a921d8a13c52d26017f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d697865726170692f637275642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mixerapi/crud)[![Build](https://github.com/mixerapi/mixerapi-dev/workflows/Build/badge.svg?branch=master)](https://github.com/mixerapi/mixerapi-dev/actions?query=workflow%3ABuild)[![Coverage](https://camo.githubusercontent.com/980eb71f87b8f84d118d946d1a90203dbc53bbc8ac87363bc543899b32c0d2a0/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d697865726170692f6d697865726170692d6465762f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/mixerapi/mixerapi-dev?branch=master)[![MixerApi](https://camo.githubusercontent.com/bca1ea90642661e0908fc7ad1c1cdbd704cda1063a2cb40801fab9d0ccdbd6af/68747470733a2f2f6d697865726170692e636f6d2f6173736574732f696d672f6d697865722d6170692d7265642e737667)](https://mixerapi.com)[![CakePHP](https://camo.githubusercontent.com/21b7bf61684c39eabf40bb424dd733f6f3a4bd11de430f8accc24ba0445b4b9b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f63616b657068702d253545342e322d7265643f6c6f676f3d63616b65706870)](https://book.cakephp.org/4/en/index.html)[![Minimum PHP Version](https://camo.githubusercontent.com/7f2179949cf3def20f5d08c400d94cf1c6c68c30bdaa05546c78e33eccded56f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e302d3838393242462e7376673f6c6f676f3d706870)](https://php.net/)

This plugin provides CRUD (Create/Read/Update/Delete) services to your RESTful APIs controller actions using [CakePHP's dependency injection container](https://book.cakephp.org/4/en/development/dependency-injection.html).

- Perform most crud operations with a single line of code.
- Automatically serializes data into JSON, XML, etc.
- Automatically enforces allowed requests `$this-request->allowMethod()`
- Crud plays nicely with existing MixerApi plugins including Pagination and CakePHP Search.
- Use of Interfaces allow you to use your own concrete implementations down the line.
- Requires CakePHP ^4.2 compatible projects.

You may also want to look at [CakePHP Crud](https://crud.readthedocs.io/en/latest/installation.html) which doesn't rely on dependency injection. If you're using this plugin without MixerApi/ExceptionRender or for a non-API projects [read below](#other-usages).

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

[](#installation)

```
composer require mixerapi/crud
bin/cake plugin load MixerApi/Crud
```

Alternatively after composer installing you can manually load the plugin in your Application:

```
# src/Application.php
public function bootstrap(): void
{
    $this->addPlugin('MixerApi/Crud');
}
```

See [Plugin Options](#plugin-options) for additional configurations.

Usage
-----

[](#usage)

Once enabled, the following services may be injected into your controller actions.

```
use MixerApi\Crud\Interfaces\{CreateInterface, ReadInterface, UpdateInterface, DeleteInterface, SearchInterface};
```

InterfaceInjected ServiceUse-casesCreateInterfaceMixerApi\\Crud\\Service\\Create`add()` actionsReadInterfaceMixerApi\\Crud\\Service\\Read`view()` actionsUpdateInterfaceMixerApi\\Crud\\Service\\Update`edit()` actionsDeleteInterfaceMixerApi\\Crud\\Service\\Delete`delete()` actionsSearchInterfaceMixerApi\\Crud\\Service\\Search`index()` actionsAll Crud services infer the table name from the controller, you can change the table name by calling the `setTableName($name)` method.

If you are using MixerApi\\ExceptionRender then an event will catch validation errors and handle the response for you, otherwise a `MixerApi\Crud\Exception\ResourceWriteException` is thrown.

See below regarding [path parameters](#path-parameters) if your path parameter is not `id`.

### Create

[](#create)

```
public function add(CreateInterface $create)
{
    $this->set('data', $create->save($this));
}
```

Note, `save()` with `$options` is supported.

```
return $create->save($this, [
    'accessibleFields' => [
        'password' => true,
    ]
]);
```

### Read

[](#read)

```
public function view(ReadInteface $read)
{
    $this->set('data', $read->read($this));
}
```

Note, `read()` with `$options` is supported.

```
return $read->save($this, ['contains' => ['OtherTable']]);
```

Return a CakePHP `Query` object instead:

```
$query = $read->query($this)
```

### Update

[](#update)

```
public function edit(UpdateInterface $update)
{
    $this->set('data', $update->save($this));
}
```

Note, `update()` with `$options` is supported.

```
return $update->save($this, [
    'accessibleFields' => [
        'password' => true,
    ]
]);
```

### Delete

[](#delete)

```
public function delete(DeleteInterface $delete)
{
    return $delete->delete($this)->respond(); // calling respond() is optional
}
```

Note, `delete()` with `$options` is supported.

```
return $delete->delete($this, ['atomic' => false]);
```

### Search

[](#search)

The Search service works with [Pagination](https://book.cakephp.org/4/en/controllers/components/pagination.html) and optionally with [CakePHP Search](https://github.com/FriendsOfCake/search).

Example:

```
public function index(SearchInterface $search)
{
    $this->set('data', $search->search($this));
}
```

To use [CakePHP Search](https://github.com/FriendsOfCake/search) initialize the component as normal in your controllers `initialize()` method.

```
$this->set('data', $search->search($this));
```

For custom CakePHP Search collections call the `setCollection($name)` method:

```
$this->set('data', $search->setCollection('collection_name')->search($this));
```

Return a CakePHP `Query` object instead:

```
$query = $search->query($this);
```

Serialization
-------------

[](#serialization)

Serialization is handled by a `Controller.beforeRender` listener. It serializes the first viewVar found for all CRUD operations and will not run for non-crud operations. See [Options](#plugin-options) for disabling serialization.

Allowed HTTP Methods
--------------------

[](#allowed-http-methods)

Allowed methods is handled by a `Controller.initialize` listener. See [Plugin Options](#plugin-options) for disabling or modifying the defaults.

ActionHTTP method(s)index()GETview()GETadd()POSTedit()POST, PUT, and PATCHdelete()DELETEYou may also call `setAllowMethods($methods)` on any service to overwrite the default behavior. This accepts a string or any array as an argument just like the native `$request->allowedMethods()`.

Plugin Options
--------------

[](#plugin-options)

You may customize functionality by passing in an options array when adding the plugin.

```
# src/Application.php

public function bootstrap(): void
{
    $this->addPlugin('MixerApi/Crud', $options);
}
```

Customize allowed HTTP methods:

```
$options = [
    'allowedMethods' => [
        'add' => ['post'],
        'edit' => ['patch'],
        'delete' => ['delete'],
    ]
];
```

To disable automatic `$request->allowMethod()` entirely:

```
$options = [
    'allowedMethods' => []
];
```

Disable automatic serialization:

```
$options = [
    'doSerialize' => false, // default is true
];
```

Misc
----

[](#misc)

#### Path Parameters

[](#path-parameters)

If your path parameter for the resource is not `id` then pass the identifier as the second argument:

```
public function view(ReadInteface $read, string $id)
{
    $this->set('data', $read->read($this, $id));
}
```

The above also works for Update and Delete.

#### Other Usages

[](#other-usages)

This plugin works best with API projects using MixerApi/ExceptionRender which uses events to set the response in the event of an error. If your project isn't using ExceptionRender or you're not an API you can write a custom exception renderer and look for `ResourceWriteException`, then alter the `viewVars` output using the `EntityInterface` from `ResourceWriteException::getEntity()`.

Read the [CakePHP Custom ExceptionRenderer](https://book.cakephp.org/4/en/development/errors.html#custom-exceptionrenderer)documentation for more information.

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance84

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity69

Established project with proven stability

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

Recently: every ~182 days

Total

18

Last Release

92d ago

Major Versions

v0.3.0 → v1.0.02022-01-16

v1.1.7 → v2.0.02024-02-17

PHP version history (3 changes)v0.3.0PHP &gt;=7.2

v1.0.0PHP ^8.0

v2.0.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/171294?v=4)[Chris Nizzardini](/maintainers/cnizzardini)[@cnizzardini](https://github.com/cnizzardini)

---

Top Contributors

[![cnizzardini](https://avatars.githubusercontent.com/u/171294?v=4)](https://github.com/cnizzardini "cnizzardini (15 commits)")

---

Tags

calephpcrudphprestrest-api

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mixerapi-crud/health.svg)

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

###  Alternatives

[friendsofcake/crud

CakePHP Application development on steroids - rapid prototyping / scaffolding &amp; production ready code - XML / JSON APIs and more

3751.4M25](/packages/friendsofcake-crud)[dereuromark/cakephp-setup

A CakePHP plugin containing lots of useful management tools

36162.8k2](/packages/dereuromark-cakephp-setup)[friendsofcake/crud-view

View layer for CRUD

52433.8k2](/packages/friendsofcake-crud-view)[arodu/cakelte

CakeLTE: AdminLTE plugin for CakePHP

3626.9k](/packages/arodu-cakelte)[dereuromark/cakephp-translate

A CakePHP plugin for managing translations

1710.4k](/packages/dereuromark-cakephp-translate)[xety/xeta

A resource to help people starting with Cake3

531.4k](/packages/xety-xeta)

PHPackages © 2026

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