csgt / crud
CRUD implementation
Requires
- php: >=7.2
Requires (Dev)
- illuminate/database: ^8.0 || ^9.0 || ^10.0
- illuminate/routing: ^8.0 || ^9.0 || ^10.0
- phpunit/phpunit: ^9.6 || ^10.5
This package is auto-updated.
Last update: 2026-08-27 14:39:40 UTC
README
This package is used to generate cruds.
You are on branch
master— package version8.0(tagsv8.0.x).
| Version | BS | Datatables | Methods | Views engine | Crypt | Constructor | UTC | Validation |
|---|---|---|---|---|---|---|---|---|
| 5.5 | 3 | 1.x | es | blade | yes | yes | no | formvaldiation |
| 5.6 | 4 | 1.x | es | blade | yes | yes | no | formvaldiation |
| 5.9 | 4 | 1.x | es | blade | yes | no | no | laravel |
| 6.0 | 4 | 1.x | en | blade | yes | yes | no | formvaldiation |
| 7.0 Beta | 4 | 1.x | en | vue | yes | yes | no | formvaldiation |
| 8.0 | 4/5 | 2.x | en | blade | no | no | yes | laravel |
Documentation for contributors
| Document | Read it for |
|---|---|
| docs/ARCHITECTURE.md | How the package is wired: request lifecycle, field metadata, the listing query |
| docs/METHODS.md | What every method of CrudController does on this branch |
| docs/RULES.md | What you may and may not change: no repurposing methods, behaviour changes go to a new version branch, legacy compatibility first |
Requirements
This branch (master, package version 8.0) requires:
| Requirement | Supported |
|---|---|
| PHP | >= 7.2 |
| Laravel | >= 5.8 (no upper bound declared; shipped against 8.x) |
| Frontend | Bootstrap 4/5 + jQuery + DataTables 2.x |
Compatibility matrix
The branch number is the package version, not the Laravel version. Each package version lives in its own branch and is released from it.
| Package version | Branch | PHP | Laravel | Status |
|---|---|---|---|---|
| 8.0 | master |
>= 7.2 |
>= 5.8 |
Active |
| 7.0 Beta | 7.x |
>= 7.2 |
>= 7.0 |
Active (Vue views, paginated response) |
| 6.0 | 6.0 |
>= 7.2 |
>= 5.8 |
Maintenance |
| 5.9 | 5.9 |
>= 7.1 |
>= 6.0 |
Maintenance |
| 5.8 | 5.8 |
>= 7.1 |
>= 5.8 |
Maintenance |
| 5.7 | 5.7 |
>= 7.1 |
>= 5.8 |
Maintenance |
| 5.6 | 5.6 |
>= 7.0 |
>= 5.5 |
Legacy |
| 5.5 | 5.5 |
>= 7.0 |
>= 5.5 |
Legacy |
| 5.4 | 5.4 |
>= 5.6 |
>= 5.4 |
Legacy |
| 5.3 | 5.3 |
>= 5.5 |
>= 5.1 |
Legacy |
| 5.0 | 5.0 |
>= 5.5 |
>= 5.0 |
Archived |
The Laravel floor is inferred from the framework APIs each branch actually
calls, since the composer.json constraints were never updated:
- Package auto-discovery (
extra.laravel.providers) → Laravel>= 5.5 Storage::disk()->temporaryUrl()→ Laravel>= 5.4BelongsTo::getOwnerKeyName()→ Laravel>= 5.8Relation::getRelationExistenceQuery()→ Laravel>= 5.5Paginator::withQueryString()→ Laravel>= 7.0Form::helpers (laravelcollective/html) on5.0–5.4→ Laravel5.xonly
Installation
composer require csgt/crud
The service provider is registered through package auto-discovery. To publish the translations:
php artisan vendor:publish --provider="Csgt\Crud\CrudServiceProvider" --tag=lang
Usage
To create a new CRUD, you may use the php artisan make:crud ExampleController command. This will set up a boilerplate
public function setup(Request $request)
{
//Required. Set the model to render
$this->setModel(new Model);
$this->setTitle('Title');
//This will render an extra button next to the Add button
$this->setExtraAction(['url' => '/module/import', 'title' => 'Importar']);
//Render the breadcrumb according to BS version
$this->setBreadcrumb([
['url' => '', 'title' => 'Catálogos', 'icon' => 'fa fa-book'],
['url' => '', 'title' => 'Titulo', 'icon' => 'fa fa-university'],
]);
//Set columns to show
$this->setField(['name' => 'Nombre', 'field' => 'name']);
$this->setField(['name' => 'Descripción', 'field' => 'descripcion']);
//Set combobox field
$this->setField([
'name' => 'Protocol',
'field' => 'protocol_id',
'type' => 'combobox',
'collection' => Protocol::select('id', 'name')->get(),
]);
//Campo Multi:
$this->setField(['name' => 'Requirements', 'type' => 'multi', 'field' => 'relationName']);
requiere en el modelo, crear la relation belongsToMany relationName
requiere en el modelo, crear el método fetchRelationName
opcional, si la columna para mostrar en el show, no se llama 'name'
crear el método fetchRelationNameColumn y retorne el campo deseado.
//Set hidden variables to append to inserts and updates
$this->setHidden(['field' => 'client_id', 'value' => 1]);
//Set extra button for each row in the Crud
$this->setExtraButton([
'url' => '/configuration/sensors?gateway_id={id}',
'icon' => 'fa fa-thermometer',
'title' => 'Sensors',
'class' => 'btn-warning',
]);
//Set permissions using the ['edit' => true, 'create' => true, 'delete' => true] syntax
$this->setPermissions(Cancerbero::crudPermissions('module'));
}
Listing performance
The data() endpoint resolves search, ordering and pagination in the
database:
- The DataTables global search becomes a
WHERE ... LIKEclause, and relation columns are matched throughwhereHas. - Ordering by a relation column uses a correlated subquery instead of sorting in memory.
- Only the requested page is fetched (
offset+limit). multifields are eager loaded, removing the N+1 query per row.
Previously the whole table was loaded into memory and filtered/sorted with
Collection methods, so the cost grew with the total number of rows instead of
the page size. No public API changed: setField, setWhere, setOrderBy and
the JSON response shape are the same.
Column filters
The listing no longer uses the DataTables global search box. Instead the view
sends a list of column/value pairs as filters[], and each one becomes a
WHERE clause:
- a plain column becomes
column LIKE ? - a relation column (
relation.column,isforeign) is matched withwhereHas - a
multifield is matched against its related column, also withwhereHas - a raw expression is matched with
whereRaw, after itsAS aliasis stripped
Rows can be added and removed in the UI, they are all applied together, and the
active set is kept in the DataTables saved state. recordsFiltered is only
recounted when at least one filter is actually applied. Filters for fields with
type => 'date' use the browser's native date picker and submit an ISO date
value (YYYY-MM-DD).
Tests
composer install vendor/bin/phpunit
The suite covers the methods that build the listing query, asserting on the SQL
and the bindings they produce. It needs Eloquent but never a database server:
no query is executed. PHPUnit, illuminate/database and illuminate/routing
are require-dev only, so nothing changes for consumers of the package.
Upgrade from version 6 to version 8 or from 5.6 to 5.9
Add the following includes:
use Illuminate\Http\Request;
use Csgt\Cancerbero\Facades\Cancerbero;
Rename the __construct method to:
public function setup(Request $request)
Call the setPermissions directly
$this->setPermissions(Cancerbero::crudPermissions('module'));
Remove all references to Crypt::encrypt and Crypt::decrypt if any methos were overriden.
Remove all references to validationRulesMessages or reglasmensaje
Remove the enclosing middleware. It is now unnecessary.
$this->middleware(function ($request, $next) {
return $next($request);
});