swattech/crud

Enterprise-grade Crud generator for Laravel 12 with theme integration

v1.0.0 2025-03-07 09:15 UTC

This package is auto-updated.

Last update: 2025-04-17 11:19:31 UTC


README

Version PHP Laravel License Tests Code Quality

SwatTech CRUD is an enterprise-grade CRUD generator for Laravel 12 with Vuexy theme integration. It analyzes your database schema and automatically detects relationships, generating feature-rich code with a single command.

๐Ÿ“‹ Comprehensive Features

Core Generation

  • ๐Ÿš€ Complete CRUD Operations - Models, controllers, repositories, services, views, and routes
  • ๐Ÿ”„ Smart Relationship Detection - Auto-detects and implements all relationship types
  • ๐Ÿงฉ Repository Pattern - Clean, maintainable code structure with caching implementation
  • ๐Ÿ“ฑ Responsive Views - Mobile-friendly interfaces with Vuexy theme components
  • ๐Ÿงช Test Suite Generation - Unit, feature, API, and browser tests with realistic data

Advanced Features

  • ๐Ÿ“ Smart Validation - Form request classes with context-aware rules based on schema
  • ๐Ÿ” Powerful Filtering - Advanced search, column filtering, and custom scopes
  • ๐Ÿ“Š Data Export - CSV, Excel, PDF export with customizable formatting
  • ๐Ÿ”’ Authorization - Policy generation with ownership checks and role integration
  • ๐Ÿ“ก API Resources - RESTful API endpoints with proper resources and transformers
  • ๐Ÿ“š Documentation - Auto-generated API and usage documentation

Enterprise Features

  • ๐Ÿ“œ Activity Logging - Comprehensive audit trail system for all operations
  • ๐Ÿ“‚ Media Management - File upload and management with preview support
  • ๐Ÿ”„ Soft Deletes - Trash management with restore capabilities
  • ๐ŸŒ Internationalization - Multi-language support with translation management
  • ๐Ÿ“Š Batch Operations - Process records in bulk with progress tracking
  • ๐Ÿ”„ Versioning - Track changes with version history and comparison

UI Components

  • ๐Ÿ“‹ Data Tables - Sortable, filterable data tables with pagination
  • ๐Ÿ“‘ Tabs & Cards - Organized content with tabbed interfaces
  • ๐Ÿ” Advanced Filters - Date ranges, multi-select filters, saved queries
  • ๐Ÿ“ค Export Buttons - One-click data export to multiple formats
  • ๐Ÿ“ Rich Forms - Date pickers, wysiwyg editors, select2 dropdowns
  • ๐Ÿ”” Notifications - User notification system with real-time updates

๐Ÿ”ง Installation

Prerequisites

  • PHP 8.1 or higher
  • Laravel 12.x
  • Composer 2.0+
  • Database connection configured in your .env file

Step 1: Install via Composer

composer require swattech/crud

Step 2: Publish Configuration

php artisan vendor:publish --provider="SwatTech\Crud\SwatTechCrudServiceProvider" --tag="config"

Step 3: Publish Assets (Optional)

php artisan vendor:publish --provider="SwatTech\Crud\SwatTechCrudServiceProvider" --tag="assets"

Step 4: Run Migrations (Optional)

Only needed if you want to use activity logging, media, etc.

php artisan migrate

โš™๏ธ Configuration

The package is highly customizable through the config/crud.php file:

// 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...
];

๐Ÿš€ Usage Examples

Generate Complete CRUD

Generate all files for a table:

php artisan crud:generate products

This will create:

  • Model with relationships
  • Repository and Service classes
  • Controller with CRUD actions
  • Form Request validation classes
  • Blade views with Vuexy theme
  • Routes in web.php
  • Factory and Seeder
  • Policy for authorization
  • Tests for all components

Generate API Only

Create API endpoints and resources:

php artisan crud:api products

Generate with Specific Options

Customize the generation process:

php artisan crud:generate products --with-api --skip-views --force

Generate for Multiple Tables

Process all tables in your database:

php artisan crud:generate --all

Generate Only Relationships

Add relationship methods to existing models:

php artisan crud:relationships products

Generate Documentation

Create comprehensive documentation:

php artisan crud:docs products

๐Ÿ“š Command Reference

crud:generate

php artisan crud:generate {table?} 
                          {--all : Generate CRUD for all tables}
                          {--connection= : Database connection to use}
                          {--path= : Custom output path}
                          {--namespace= : Custom namespace}
                          {--with-api : Generate API endpoints}
                          {--with-tests : Generate tests}
                          {--model : Generate only model}
                          {--controller : Generate only controller}
                          {--repository : Generate only repository}
                          {--service : Generate only service}
                          {--views : Generate only views}
                          {--factory : Generate only factory}
                          {--migration : Generate only migration}
                          {--seeder : Generate only seeder}
                          {--policy : Generate only policy}
                          {--resource : Generate only API resource}
                          {--request : Generate only form requests}
                          {--observer : Generate only observer}
                          {--event : Generate only events}
                          {--listener : Generate only listeners}
                          {--job : Generate only jobs}
                          {--force : Overwrite existing files}
                          {--dry-run : Run without creating any files}
                          {--theme= : Specify the theme for views (default: vuexy)}

crud:api

Generate API-specific components:

php artisan crud:api {table?}
                     {--all : Generate API for all tables}
                     {--connection= : Database connection to use}
                     {--controller : Generate only API controller}
                     {--resource : Generate only API resource}
                     {--documentation : Generate only API documentation}
                     {--transformer : Generate only API transformers}
                     {--version= : API version (default: v1)}
                     {--versions= : Multiple API versions separated by comma}
                     {--prefix= : API route prefix}
                     {--middleware= : API middleware to apply}
                     {--auth= : Authentication type (token, sanctum, passport, jwt)}
                     {--format= : Response format (json, jsonapi)}
                     {--collection : Generate resource collection}
                     {--swagger : Generate Swagger/OpenAPI documentation}
                     {--force : Overwrite existing files}

crud:relationships

Analyze and generate relationships:

php artisan crud:relationships {table?}
                              {--all : Generate relationships for all tables}
                              {--connection= : Database connection to use}
                              {--detect : Auto-detect relationships only}
                              {--inverse : Generate inverse relationships}
                              {--force : Overwrite existing methods}

crud:docs

Generate comprehensive documentation:

php artisan crud:docs {table?}
                      {--all : Generate documentation for all tables}
                      {--api : Generate only API documentation}
                      {--schema : Generate only database schema documentation}
                      {--relationships : Generate only relationship diagrams}
                      {--crud : Generate only CRUD operations documentation}
                      {--validation : Generate only validation rules documentation}
                      {--ui : Generate only UI user guides}
                      {--format= : Documentation format (markdown, html, pdf)}
                      {--output= : Output directory for documentation files}
                      {--force : Overwrite existing documentation files}

crud:tests

Generate test suite:

php artisan crud:tests {table?}
                       {--all : Generate tests for all tables}
                       {--connection= : Database connection to use}
                       {--unit : Generate only unit tests}
                       {--feature : Generate only feature tests}
                       {--api : Generate only API tests}
                       {--browser : Generate only browser tests}
                       {--force : Overwrite existing test files}

๐Ÿ”Œ Extending and Customizing

Custom Generators

Extend the base generator classes to customize the code generation:

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;
    }
}

Register your custom generator in a service provider:

// In AppServiceProvider or custom service provider
public function register()
{
    $this->app->bind(
        \SwatTech\Crud\Generators\ModelGenerator::class,
        \App\Generators\CustomModelGenerator::class
    );
}

Custom Stubs

Publish and edit the stub templates:

php artisan vendor:publish --provider="SwatTech\Crud\SwatTechCrudServiceProvider" --tag="stubs"

Edit the stubs in resources/stubs/vendor/swattech/crud/:

  • Controllers: controller.stub, api_controller.stub
  • Models: model.stub
  • Views: views/index.blade.stub, views/create.blade.stub, etc.
  • And many more...

Custom Themes

The package comes with Vuexy theme integration by default, but you can create your own theme:

  1. Publish the stubs: php artisan vendor:publish --tag="stubs"
  2. Create a new theme directory: resources/stubs/vendor/swattech/crud/mytheme/
  3. Add your theme files (layout.stub, views/, components/)
  4. Update configuration: 'theme' => ['name' => 'mytheme']

โ“ Troubleshooting

Class Not Found Errors

composer dump-autoload

Permission Issues

chmod -R 755 app/
chmod -R 755 resources/

Database Connection Issues

Make sure your .env file has the correct database configuration:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database
DB_USERNAME=your_username
DB_PASSWORD=your_password

JavaScript/CSS Assets Not Found

php artisan vendor:publish --provider="SwatTech\Crud\SwatTechCrudServiceProvider" --tag="assets" --force
npm install
npm run dev

Relationship Detection Issues

If relationships aren't detected properly:

php artisan crud:relationships your_table --detect --verbose

Customizing Generated Code

To make minor changes without extending classes:

  1. Publish the config: php artisan vendor:publish --tag="config"
  2. Publish the stubs: php artisan vendor:publish --tag="stubs"
  3. Edit the appropriate stub files
  4. Update the config to use custom stubs: 'stubs' => ['use_custom' => true]

๐Ÿ“ License

The SwatTech CRUD package is open-sourced software licensed under the MIT license.

๐Ÿ‘ฅ Contributing

We welcome contributions to improve SwatTech CRUD! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Commit your changes: git commit -m 'Add feature'
  4. Push to the branch: git push origin feature-name
  5. Submit a pull request

Please make sure your code follows our coding standards and includes appropriate tests.

๐Ÿ“ฆ Credits

  • Developed by Swat Info System
  • Made with โค๏ธ for Laravel developers