PHP code example of ebalo / easycrud

1. Go to this page and download the library: Download ebalo/easycrud library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ebalo / easycrud example snippets


namespace App\Http\Controllers;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
// ...

class CategoryController extends Controller
{
    // Validation rules array, inherited from the EasyCRUD trait
    protected array $rules = [
        "name" => " to create
            "categories-index"      // Redirect if validation and creation ends successfully
        );
    }
    
    public function update(Request $request, Category $category): RedirectResponse
    {
        return $this->easyUpdate(
            $request,               // Request to validate
            $category,              // Model to update
            "categories-index"      // Redirect if validation and creation ends successfully
        );
    }
    
    public function destroy(Category $category): RedirectResponse
    {
        return $this->easyDelete(
            $category,              // Model to update
            "categories-index"      // Redirect if validation and creation ends successfully
        );
    }
    
    // ...
}

namespace App\Http\Controllers;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
// ...

class CategoryController extends Controller
{
    // Validation rules array, inherited from the EasyCRUD trait
    protected array $rules = [
        "name" => "to create
            "create",               // Creation function
            "categories-index"      // Redirect if validation and creation ends successfully
        );
    }
    
    // ...
}

namespace App\Http\Controllers;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
// ...

class CategoryController extends Controller
{
    // Note the that $rules now is marked as private
    private array $rules = [
        "name" => "    // Request to validate
            $this->rules,           // Array of validation rules
            Category::class,        // Model to create
            "categories-index"      // Redirect if validation and creation ends successfully
        );
    }

    public function update(Request $request, Category $category): RedirectResponse
    {
        return easyUpdate(
            $this,                  // Instance of the caller class
            $request,               // Request to validate
            $this->rules,           // Array of validation rules
            $category,              // Model to update
            "categories-index"      // Redirect if validation and creation ends successfully
        );
    }

    public function destroy(Category $category): RedirectResponse
    {
        return easyDelete(
            $category,              // Model to delete
            "categories-index"      // Redirect if validation and creation ends successfully
        );
    }
}

namespace App\Http\Controllers;

use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
// ...

class CategoryController extends Controller
{
    // Validation rules array, inherited from the EasyCRUD trait
    protected array $rules = [
        "name" => "est to validate
            $this->rules,           // Array of validation rules
            Category::class,        // Model to create
            "create",               // Creation function
            "categories-index"      // Redirect if validation and creation ends successfully
        );
    }
    
    // ...
}

use App\Http\Controllers\CategoryController;
// ...

CRUD(
    "categories",                   // Route path prefix
    CategoryController::class,      // Controller class to call
    "category",                     // Route name prefix
    "category"                     // Parameter name for the routes that 

use App\Http\Controllers\CategoryController;
// ...

Route::prefix("/categories")->group(function() {
     Route::get("/", [CategoryController::class, "index"])->name("category-list");
     Route::get("/{category}", [CategoryController::class, "show"])->name("category-show");
     
     Route::get("/create", [CategoryController::class, "create"])->name("category-create");
     Route::post("/create", [CategoryController::class, "store"])->name("category-store");
     
     Route::get("/edit/{category}", [CategoryController::class, "edit"])->name("category-edit");
     Route::put("/edit/{category}", [CategoryController::class, "update"])->name("category-update");
     
     Route::delete("/delete/{category}", [CategoryController::class, "destroy"])->name("category-delete");
});
// ...

use App\Http\Controllers\CategoryController;
// ...

CRUD(
    "categories",                   // Route path prefix
    CategoryController::class,      // Controller class to call
    "categories",                   // Route name prefix
    "category",                     // Parameter name for the routes that    "delete" => true           // Don't register the deletion endpoints
    ]
);
// ...

use App\Http\Controllers\CategoryController;
// ...

Route::prefix("/categories")->group(function() {     
     Route::get("/create", [CategoryController::class, "create"])->name("categories-create");
     Route::post("/create", [CategoryController::class, "store"])->name("categories-store");
     
     Route::delete("/delete/{category}", [CategoryController::class, "destroy"])->name("categories-delete");
});
// ...

use App\Http\Controllers\CategoryController;
// ...

CRUD(
    "categories",                   // Route path prefix
    CategoryController::class,      // Controller class to call
    "categories",                   // Route name prefix
    "category",                     // Parameter name for the routes that    "delete" => false            // Don't register the deletion endpoints
    ],
    $functions = [
        "list" => "list_function",
        "read" => "read_function",
        "create" => "creation_function",
        "store" => "store",
        "edit" => "edit",
        "update" => "update",
        "delete" => "destroy"
    ]
);
// ...

use App\Http\Controllers\CategoryController;
// ...

Route::prefix("/categories")->group(function() {     
     Route::get("/create", [CategoryController::class, "creation_function"])->name("categories-create");
     Route::post("/create", [CategoryController::class, "store"])->name("categories-store");
});
// ...
bash
php artisan easy-crud:install