PHP code example of swattech / crud

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

    

swattech / crud example snippets


// config/crud.php

return [
    // Path configurations for generated files
    'paths' => [
        'models' => 'app/Models',
        'controllers' => [
            'web' => 'app/Http/Controllers',
            'api' => 'app/Http/Controllers/API',
        ],
        'views' => 'resources/views',
        // Additional paths...
    ],
    
    // Namespace configurations
    'namespaces' => [
        'models' => 'App\\Models',
        // Additional namespaces...
    ],
    
    // Model settings
    'models' => [
        'soft_deletes' => true, 
        'timestamps' => true,
        'with_factory' => true,
        // Additional model settings...
    ],
    
    // Theme settings
    'theme' => [
        'name' => 'vuexy',
        'assets' => [
            // Theme assets...
        ],
    ],
    
    // Additional configuration options...
];

namespace App\Generators;

use SwatTech\Crud\Generators\ModelGenerator as BaseModelGenerator;

class CustomModelGenerator extends BaseModelGenerator
{
    public function getStub(string $filename = ""): string
    {
        return resource_path('stubs/custom-model.stub');
    }
    
    public function buildClass(string $table, array $schema, array $relationships): string
    {
        // Custom implementation
        $content = parent::buildClass($table, $schema, $relationships);
        
        // Add your customizations
        $content = str_replace(
            '// Custom traits',
            'use App\\Traits\\CustomTrait;',
            $content
        );
        
        return $content;
    }
}

// In AppServiceProvider or custom service provider
public function register()
{
    $this->app->bind(
        \SwatTech\Crud\Generators\ModelGenerator::class,
        \App\Generators\CustomModelGenerator::class
    );
}
bash
php artisan vendor:publish --provider="SwatTech\Crud\SwatTechCrudServiceProvider" --tag="config"
bash
php artisan vendor:publish --provider="SwatTech\Crud\SwatTechCrudServiceProvider" --tag="assets"
bash
php artisan migrate
bash
php artisan crud:generate products
bash
php artisan crud:api products
bash
php artisan crud:generate products --with-api --skip-views --force
bash
php artisan crud:relationships products
bash
php artisan crud:docs products
bash
php artisan vendor:publish --provider="SwatTech\Crud\SwatTechCrudServiceProvider" --tag="stubs"
bash
composer dump-autoload