sajjadgozal/simple-crud

add simple vies of crud based apps

v1.0.2 2021-11-09 07:03 UTC

This package is auto-updated.

Last update: 2025-07-23 06:10:37 UTC


README

add simple vies of crud based apps

install

install with command :

composer require sajjadgozal/simplecrud

for publishing views and config :

php artisan vendor:publish --tag=sajjadgozal\SimpleCrud\SimpleCrudServiceProvider

Uesage

Add hasCrud trait to model to enable croud routes and views for that model. And dont forget to add fillable variables.

Category model :

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use sajjadgozal\SimpleCrud\traits\hasCrud;

class Category extends Model
{
    use hasCrud;

    protected fillable = [] ;
    
}

and you can use links to work with model objects.

    {{app_address}}/{{prefix}}/{{model_name}} 

example:

    http://127.0.0.1:8000/crud/category
    
    http://127.0.0.1:8000/crud/category/1/
    
    http://127.0.0.1:8000/crud/category/1/edit
    

Configuration

route prefix can be changed from config/simplecrud.php file.

default:

    'route_prefix' => 'crud',

example:

    'route_prefix' => '',

or

    'route_prefix' => 'custom_prefix',

api prefix can be changed from config/simplecrud.php file.

    'api_route_prefix'=>'crud-api',

Views

By default, package will use view files in universal folder. you can add view files with names: "index.blade.php","show.blade.php","create.blade.php","edit.blade.php" in the folder with model name in resources/views/ folder.

example:

    resources/views/category/show.blade.php

Validation

for ading validation rules for model , add parameter rules to the model. like as laravel validation rules.

examole:

class Item extends Model
{
    use hasCrud;

    protected $fillable =[
        'name',
        'number'
    ];
    
    /**
     *  Get the validation rules that apply to the request.
     *
     * @var string[]
     */
    public $rules = [
        'name' => 'required|string',
        'number' => 'sometimes|numeric'
    ];
}

api

api routes are returning json

    {{app_address}}/{{api-prefix}}/{{model_name}} 

example:

    http://127.0.0.1:8000/crud-api/category

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.