PHP code example of zaidysf / zcrudgen

1. Go to this page and download the library: Download zaidysf/zcrudgen 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/ */

    

zaidysf / zcrudgen example snippets


return [
    'namespace' => 'App',
    'paths' => [
        'model' => app_path('Models'),
        'controller' => app_path('Http/Controllers/API'),
        // ...
    ],
    'auth' => [
        'middleware' => [
            'enabled' => true,
            'default' => ['auth:sanctum'],
        ],
        'permissions' => [
            'enabled' => true,
            'prefix' => ['create', 'read', 'update', 'delete'],
        ],
    ],
    'swagger' => [
        'enabled' => true,
        'version' => '3.0.0',
    ],
    'ai' => [
        'enabled' => false,
        'api_key' => env('OPENAI_API_KEY'),
        'model' => 'gpt-4',
    ],
];

// Filter by exact match
/api/users?name=John

// Filter by date range
/api/users?created_at[from]=2024-01-01&created_at[to]=2024-12-31

// Filter by relationship
/api/cities?country_id=1

// Multiple filters
/api/users?status=active&role=admin

public function create(array $data): Model
{
    // AI-generated validation
    $this->validateCreationRules($data);

    // AI-suggested caching strategy
    $cacheKey = "product:{$data['sku']}";
    
    if (Cache::has($cacheKey)) {
        throw new DuplicateProductException();
    }

    DB::beginTransaction();
    try {
        $product = $this->repository->create($data);
        
        // AI-suggested event
        ProductCreated::dispatch($product);
        
        Cache::put($cacheKey, $product, now()->addDay());
        
        DB::commit();
        return $product;
    } catch (\Exception $e) {
        DB::rollBack();
        throw $e;
    }
}

'swagger' => [
    'enabled' => true,
    'version' => '3.0.0',
    'title' => 'Your API Title',
    'description' => 'Your API Description',
],
bash
php artisan zcrudgen:make User
bash
php artisan zcrudgen:make Product --middleware="auth:sanctum,verified"
bash
php artisan zcrudgen:make Order --permissions
bash
php artisan zcrudgen:make Product --middleware="auth:sanctum,verified,custom"