PHP Classes

Laravel CRUD Tools: Provides components to build CRUD interfaces

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-07-28 (6 months ago) RSS 2.0 feedNot enough user ratingsTotal: 118 All time: 9,534 This week: 66Up
Version License PHP version Categories
crud-tools 0.0.19MIT/X Consortium ...7.1PHP 5, Libraries
Description 

Author

This package provides components to build CRUD interfaces.

It provides trait to use in a controller class that comes with regular functions to implement CRUD operations like create new records, list records, edit records and delete records.

The package also comes with traits to implement CRUD action logging and storage access functions like validating record data and searching for records based on criteria.

Picture of Thiago Przyczynski
  Performance   Level  
Name: Thiago Przyczynski <contact>
Classes: 16 packages by
Country: Brazil Brazil
Innovation award
Innovation award
Nominee: 8x

Documentation

Laravel Crud Tools

Easy to use Laravel CRUD package with Controller, Model and Log system built in.

Documentation Status Dev Master

Table of contents

Installation

Install through composer using: `composer install thiagoprz/crud-tools`

If you don't have package auto discovery enabled add CrudToolsServiceProvider to your config/app.php:

... 
'providers' => [
    ...
    \Thiagoprz\CrudTools\CrudToolsServiceProvider::class,
],
...

Publish Crud Tools service provider to allow stubs customization:

` php artisan vendor:publish --provider="Thiagoprz\CrudTools\CrudToolsServiceProvider"`

Usage

CRUD Model:

For models you just need to add the trait ModelCrud and after that create a static property declaring model's validations (based on the create, update and/or delete scenarios), default order, filtering rules, upload file rules, define resources, and with / countable relationships.

  • Validations:
    <?php
    ...
    use Thiagoprz\CrudTools\Models\ModelCrud;
    use Thiagoprz\CrudTools\Interfaces\ModelCrudInterface;
    class User extends Authenticatable implements ModelCrudInterface
    {
    use ModelCrud;
    
    /
     * Model validations
     *
     * @var array
     */
    static $validations = [
        'create' => [
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
        ],
        'update' => [
            'name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
        ],
    ];
    ...
    }
    
  • Searchable fields:

You can create a $searchable property that will hold fields allowed to be searched on the static method search() - very useful with the ControllerCrud.

<?php
...
use Thiagoprz\CrudTools\Models\ModelCrud;
class User extends Authenticatable
{
    use ModelCrud;
    /
     * Fields that can be searched by (static)method search()
     *
     * @var array
     */
    static $searchable = [
        'id' => 'int',
        'name' => 'string',
        'created_at' => 'datetime',
    ];
    ...
}

  • Range searchable fields:

Types available: int, string, date, datetime and decimal.

You can use input filters using "_from" and "_to" suffix on date, datetime and decimal fields:

<!-- Filtering created_at usig field "from" ( where created_at >= $created_at_from ) -->
<label>Period from: </label>
<input type="date" name="created_at_from">

<!-- Filtering created_at usig field "to" ( where created_at <= $created_at_to ) -->
<label>To:</label>
<input type="date" name="created_at_to">

| Type | Description | Suffixes: _from _to | | --------- | ------------------- | ------------------- | | int | Integer fields, can be used to search a range of records by using "_from" and "_to" suffixes | Yes | | decimal | Float, Double, Real or any decimal type of field. "_from" and "_to" suffixes allowed | Yes | | string | Any string field to be search using "WHERE field LIKE '%SEARCH%'" | No | | string | Any string field to be search using "WHERE field = 'SEARCH'" | No | | datetime | Datetime and Timestamp fields | Yes | | date | Date fields | Yes |

  • Custom searchable field methods:

In addition to use standard search based on type of fields you can add your on custom methods to customize search of specific fields. Create a method called "searchField" where Field is the name of the field with only first letter upper case.

Example:

<?php
...
use Thiagoprz\CrudTools\Models\ModelCrud;
class Books extends Model
{
    ...
    
    /
     * Searching only by the start of the title of the book with LIKE
     */
    public static function searchTitle($query, $title)
    {
        $query->where('title', 'LIKE', "$title%");    
    }

}


  • Sortable fields:

You can define the fields that will be used as default sorting of your model on the index action. Also, you can pass an "order" input used by the search method allowing the override the default order defined by this variable.

<?php
...
use Thiagoprz\CrudTools\Models\ModelCrud;
use Thiagoprz\CrudTools\Interfaces\ModelCrudInterface;
class Books extends Model implements ModelCrudInterface
{
    use ModelCrud;
    /
     * Default order
     *
     * @var array
     */
    static $search_order = [
        'title' => 'ASC',
        'updated_at' => 'DESC',
        'created_at' => 'DESC',
    ];
    ...
}

  • Upload fields:

You can create a fileUploads method to define which and where your uploadable fields will store the files:

<?php
...
use Thiagoprz\CrudTools\Models\ModelCrud;
use Thiagoprz\CrudTools\Interfaces\ModelCrudInterface;
class User extends Authenticatable implements ModelCrudInterface
{
    use ModelCrud;
    ...
    /
     * @param Campaign $model
     * @return array
     */
    public static function fileUploads(Campaign $model)
    {
        return [
            'FIELD_NAME' => [
                'path' => 'FOLDER', // Mandatory
                'name' => 'FILE_NAME', // (OPTIONAL)if not provided will be the file original name 
            ],
        ];
    }
    ...
}

CRUD Controller:

A CRUD Controller can be achieve by just creating a standard controller class using ControllerCrud trait.

The next step is to create a folder inside `resources/views` with the desired namespace or on root folder if the controller won't be using a specific namespace (admin on the example).

<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Thiagoprz\CrudTools\Http\Controllers\ControllerCrud;
use Thiagoprz\CrudTools\Interfaces\ControllerCrudInterface;

class UserController extends Controller implements ControllerCrudInterface
{
    use ValidatesRequests;
    use ControllerCrud;
    public $modelClass = User::class;
}

Views directory structure used by Controller CRUD based on the above example:

Folder: > views/admin/user

Files: > create.blade.php

> edit.blade.php

Available vars: $model (the model being updated)

> form.blade.php

Available vars: $model (the model being updated - only on edit action)

> index.blade.php

Available vars: $items (the pagination object containing a filtered collection of the model)

> show.blade.php

Available vars: $model (the model being displayed)

CRUD Generators

Model Generator:

To easily create a model with all Crud Tools enabled use:

php artisan make:crud-model NAMESPACE/Model   

> NAMESPACE: Model's namespace > Model: Name of the model

  • Available options - --fillable: comma separated fields for fillable attributes - --searchable: comma separated fields for searchable attributes (based on search() method) - --primaryKey: field or comma separated fields that are the table's primary key - --softDeletes: if passed enables SoftDeletes trait on class - --uploads: if passed adds fileUploads() method on class - --logable: adds Logable trait on model

Controller Generator:

You can create a standard Controller to work with a model by using the following command:


> NAMESPACE1: Controller's namespace
>
> NAMEController: is the name of the controller
>
> NAMESPACE2: Model's namespace
>
> Model: Name of the model

## Enabling Logs
To enable automatic logs on your models you need to publish Spatie Activity Logger migrations:

``php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="migrations"``

Run migrations:

``php artisan migrate``

For more information you can read Spatie Activity Log Documentations.


## Customizing Routes and Resource Paths
If you need to have different structure for resource directories besides the default `resources/{namespace/}modelname/` you can implement the method getViewPath on your controller and define it up manually: 

/
 * @param $forRedirect
 * @return string
 */
public function getViewPath($forRedirect = false): string
{
    return $forRedirect ? 'custom/url' : 'custom.path';
}
This method returns the path for routes and views, so you can customize the url and path for resources separatelly just using `$forRedirect` `true` for routes and `false` for resource directories.


## Contributing
Check the contributing file to have a better understanding on how to contribute to the package.

## Support

### Issues
Please feel free to indicate any issues on this packages, it will help a lot. I will address it as soon as possible.

### Supported By Jetbrains
This project is being developed with the help of Jetbrains through its project to support Open Source software.

Test Image 1

### Buy me a Coffee
ko-fi
buy-coffee


  Files folder image Files (80)  
File Role Description
Files folder image.github (1 file, 1 directory)
Files folder imagedatabase (2 directories)
Files folder imagedocs (2 files, 2 directories)
Files folder imagesrc (1 file, 6 directories)
Files folder imagesupport (1 file)
Files folder imagetests (1 file, 2 directories)
Accessible without login Plain text file CODE_OF_CONDUCT.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file CONTRIBUTING.md Data Auxiliary data
Accessible without login Plain text file License.txt Doc. Documentation
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (80)  /  .github  
File Role Description
Files folder imageworkflows (2 files)
  Accessible without login Plain text file dependabot.yml Data Auxiliary data

  Files folder image Files (80)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file dev.yml Data Auxiliary data
  Accessible without login Plain text file master.yml Data Auxiliary data

  Files folder image Files (80)  /  database  
File Role Description
Files folder imagemigrations (1 file)
Files folder imagetests (2 directories)

  Files folder image Files (80)  /  database  /  migrations  
File Role Description
  Plain text file 2021_09_03_140446_...ivity_log_table.php Class Class source

  Files folder image Files (80)  /  database  /  tests  
File Role Description
Files folder imagefactories (1 file)
Files folder imagemigrations (1 file)

  Files folder image Files (80)  /  database  /  tests  /  factories  
File Role Description
  Plain text file DummyFactory.php Class Class source

  Files folder image Files (80)  /  database  /  tests  /  migrations  
File Role Description
  Plain text file create_dummy_table.php Class Class source

  Files folder image Files (80)  /  docs  
File Role Description
Files folder imagebuild (5 files, 4 directories)
Files folder imagesource (2 files)
  Accessible without login Plain text file make.bat Data Auxiliary data
  Accessible without login Plain text file Makefile Data Auxiliary data

  Files folder image Files (80)  /  docs  /  build  
File Role Description
Files folder imagehtml (5 files, 3 directories)
Files folder image_images (1 file)
Files folder image_sources (1 file)
Files folder image_static (14 files)
  Accessible without login Plain text file .buildinfo Data Auxiliary data
  Accessible without login HTML file genindex.html Doc. Documentation
  Accessible without login HTML file index.html Doc. Documentation
  Accessible without login HTML file search.html Doc. Documentation
  Accessible without login Plain text file searchindex.js Data Auxiliary data

  Files folder image Files (80)  /  docs  /  build  /  html  
File Role Description
Files folder image_images (1 file)
Files folder image_sources (1 file)
Files folder image_static (15 files)
  Accessible without login Plain text file .buildinfo Data Auxiliary data
  Accessible without login HTML file genindex.html Doc. Documentation
  Accessible without login HTML file index.html Doc. Documentation
  Accessible without login HTML file search.html Doc. Documentation
  Accessible without login Plain text file searchindex.js Data Auxiliary data

  Files folder image Files (80)  /  docs  /  build  /  html  /  _images  
File Role Description
  Accessible without login Plain text file jetbrains.svg Data Auxiliary data

  Files folder image Files (80)  /  docs  /  build  /  html  /  _sources  
File Role Description
  Accessible without login Plain text file index.rst.txt Doc. Documentation

  Files folder image Files (80)  /  docs  /  build  /  html  /  _static  
File Role Description
  Accessible without login Plain text file alabaster.css Data Auxiliary data
  Accessible without login Plain text file basic.css Data Auxiliary data
  Accessible without login Plain text file custom.css Data Auxiliary data
  Accessible without login Plain text file doctools.js Data Auxiliary data
  Accessible without login Plain text file documentation_options.js Data Auxiliary data
  Accessible without login Image file file.png Icon Icon image
  Accessible without login Plain text file jquery-3.5.1.js Data Auxiliary data
  Accessible without login Plain text file jquery.js Data Auxiliary data
  Accessible without login Plain text file language_data.js Data Auxiliary data
  Accessible without login Image file minus.png Icon Icon image
  Accessible without login Image file plus.png Icon Icon image
  Accessible without login Plain text file pygments.css Data Auxiliary data
  Accessible without login Plain text file searchtools.js Data Auxiliary data
  Accessible without login Plain text file underscore-1.13.1.js Data Auxiliary data
  Accessible without login Plain text file underscore.js Data Auxiliary data

  Files folder image Files (80)  /  docs  /  build  /  _images  
File Role Description
  Accessible without login Plain text file jetbrains.svg Data Auxiliary data

  Files folder image Files (80)  /  docs  /  build  /  _sources  
File Role Description
  Accessible without login Plain text file index.rst.txt Doc. Documentation

  Files folder image Files (80)  /  docs  /  build  /  _static  
File Role Description
  Accessible without login Plain text file alabaster.css Data Auxiliary data
  Accessible without login Plain text file basic.css Data Auxiliary data
  Accessible without login Plain text file custom.css Data Auxiliary data
  Accessible without login Plain text file doctools.js Data Auxiliary data
  Accessible without login Plain text file documentation_options.js Data Auxiliary data
  Accessible without login Image file file.png Icon Icon image
  Accessible without login Image file forkme_right_darkblue_121621.png Icon Icon image
  Accessible without login Plain text file jquery.js Data Auxiliary data
  Accessible without login Plain text file language_data.js Data Auxiliary data
  Accessible without login Image file minus.png Icon Icon image
  Accessible without login Image file plus.png Icon Icon image
  Accessible without login Plain text file pygments.css Data Auxiliary data
  Accessible without login Plain text file searchtools.js Data Auxiliary data
  Accessible without login Plain text file underscore.js Data Auxiliary data

  Files folder image Files (80)  /  docs  /  source  
File Role Description
  Accessible without login Plain text file conf.py Data Auxiliary data
  Plain text file index.rst Class Class source

  Files folder image Files (80)  /  src  
File Role Description
Files folder imageCommands (2 files)
Files folder imageconfig (1 file)
Files folder imageHttp (1 directory)
Files folder imageInterfaces (2 files)
Files folder imageModels (2 files)
Files folder imagestubs (2 files)
  Plain text file CrudToolsServiceProvider.php Class Class source

  Files folder image Files (80)  /  src  /  Commands  
File Role Description
  Plain text file MakeCrudController.php Class Class source
  Plain text file MakeCrudModel.php Class Class source

  Files folder image Files (80)  /  src  /  config  
File Role Description
  Accessible without login Plain text file crud-tools.php Aux. Auxiliary script

  Files folder image Files (80)  /  src  /  Http  
File Role Description
Files folder imageControllers (1 file)

  Files folder image Files (80)  /  src  /  Http  /  Controllers  
File Role Description
  Plain text file ControllerCrud.php Class Class source

  Files folder image Files (80)  /  src  /  Interfaces  
File Role Description
  Plain text file ControllerCrudInterface.php Class Class source
  Plain text file ModelCrudInterface.php Class Class source

  Files folder image Files (80)  /  src  /  Models  
File Role Description
  Plain text file Logable.php Class Class source
  Plain text file ModelCrud.php Class Class source

  Files folder image Files (80)  /  src  /  stubs  
File Role Description
  Plain text file Controller.stub Class Class source
  Plain text file Model.stub Class Class source

  Files folder image Files (80)  /  support  
File Role Description
  Accessible without login Plain text file jetbrains.svg Data Auxiliary data

  Files folder image Files (80)  /  tests  
File Role Description
Files folder imageconfig (1 file)
Files folder imageUnit (2 directories)
  Plain text file TestCase.php Class Class source

  Files folder image Files (80)  /  tests  /  config  
File Role Description
  Accessible without login Plain text file database.php Aux. Configuration script

  Files folder image Files (80)  /  tests  /  Unit  
File Role Description
Files folder imageHttp (1 directory)
Files folder imageModels (1 file, 1 directory)

  Files folder image Files (80)  /  tests  /  Unit  /  Http  
File Role Description
Files folder imageControllers (1 file, 1 directory)

  Files folder image Files (80)  /  tests  /  Unit  /  Http  /  Controllers  
File Role Description
Files folder imageValidations (2 files)
  Plain text file DummyController.php Class Class source

  Files folder image Files (80)  /  tests  /  Unit  /  Http  /  Controllers  /  Validations  
File Role Description
  Plain text file StoreTest.php Class Class source
  Plain text file UpdateTest.php Class Class source

  Files folder image Files (80)  /  tests  /  Unit  /  Models  
File Role Description
Files folder imageSearch (2 files)
  Plain text file Dummy.php Class Class source

  Files folder image Files (80)  /  tests  /  Unit  /  Models  /  Search  
File Role Description
  Plain text file OrderTest.php Class Class source
  Plain text file PaginationTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:118
This week:0
All time:9,534
This week:66Up