PHP Classes
elePHPant
Icontem

Laravel CRUD Tools: Provides components to build CRUD interfaces

Recommend this page to a friend!
  Info   View files Documentation   View files View files (6)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2019-07-10 (7 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 53 This week: 17All time: 9,524 This week: 14Up
Version License PHP version Categories
crud-tools 0.0.6MIT/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.

  Performance   Level  
Name: Thiago Przyczynski <contact>
Classes: 4 packages by
Country: Brazil Brazil
Age: 30
All time rank: 4054336 in Brazil Brazil
Week rank: 4 Up1 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 1x

 

Details

Laravel Crud Tools

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

Installation

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

Run after install scripts for Spatie Activity Logger:

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

Run migrations:

`php artisan migrate`

You can read Spatie Activity Log Documentations

Usage

  • 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\Models\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Thiagoprz\CrudTools\Http\Controllers\ControllerCrud;

class UserController extends Controller
{
    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 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.

<?php
...
use Thiagoprz\CrudTools\Models\ModelCrud;
class User extends Authenticatable
{
    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',
    ];
    ...
}

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;
class User extends Authenticatable
{
    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 
            ],
        ];
    }
    ...
}
  Files folder image Files  
File Role Description
Files folder imagesrc (2 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file License.txt Doc. Documentation
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageHttp (1 directory)
Files folder imageModels (2 files)

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

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

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

 Version Control Unique User Downloads Download Rankings  
 100%
Total:53
This week:17
All time:9,524
This week:14Up