Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Crud Generator Laravel Package

darshan-belani/laravel-crud-generator

Generate full Laravel CRUD modules from one command: migrations, models with relationships, resource/API controllers, Livewire components, and Bootstrap/Tailwind views. Can auto-install Breeze or Laravel UI on fresh apps. Supports Laravel 10+, PHP 8.1+.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Install the package in a Laravel 10+ project:
    composer require darshan-belani/laravel-crud-generator
    
  2. Publish optional config (for stub customization):
    php artisan vendor:publish --tag=crud
    
  3. Generate a CRUD module (interactive CLI):
    php artisan make:module posts
    
    • Follow prompts to define table name, field count, and field names.
    • Choose a stack: bootstrap, tailwind, livewire, or api.

First Use Case

Quickly scaffold a blog module with API endpoints and Tailwind views:

php artisan make:module blogs tailwind

This generates:

  • Migration (blogs table)
  • Eloquent Model (Blog with fillable fields)
  • API Controller (BlogController with store, index, etc.)
  • Tailwind Blade views (index.blade.php, create.blade.php, etc.)
  • Route definitions in web.php/api.php

Implementation Patterns

Core Workflows

1. Standard CRUD Generation

# Bootstrap 5 views
php artisan make:module users bootstrap

# Tailwind CSS views
php artisan make:module products tailwind

# Livewire components (Tailwind-based)
php artisan make:module orders livewire

# API-only (no views)
php artisan make:module reports api

2. Custom Route Naming

# Override default plural slug route
php artisan make:module admin_panels --route=admin

Generates routes like:

Route::resource('admin', AdminPanelController::class);

3. Field-Specific Customization

  • Add a relationship field (e.g., user_id):
    php artisan make:module posts
    
    • Enter user_id as a field → Generator prompts for relationship type (e.g., belongsTo).
    • Result: Eloquent relationship in Post model and foreign key in migration.

4. Bulk Module Creation

For multiple modules (e.g., posts, comments, users):

# Loop through modules in a script
php artisan make:module posts tailwind
php artisan make:module comments tailwind

Integration Tips

With Laravel Breeze/Jetstream

  • Auto-installs Breeze/UI if missing:
    composer require laravel/breeze --dev
    php artisan breeze:install
    
  • Generated CRUD modules integrate with Breeze’s auth scaffolding (e.g., middleware, views).

With Livewire

  • Livewire components are Tailwind-styled by default.
  • Extend components by modifying:
    // app/Livewire/Posts/Index.php
    public function mount() {
        $this->posts = Post::latest()->get();
    }
    

With API Testing

  • Use Laravel’s Http tests:
    public function test_create_post() {
        $response = $this->post('/api/posts', [
            'title' => 'Test Post',
            'body' => 'Content...'
        ]);
        $response->assertCreated();
    }
    

Stub Customization

  1. Publish stubs:
    php artisan vendor:publish --tag=stubs-crud
    
  2. Override templates in resources/stubs/.
  3. Update config/crud.php:
    'stub_path' => resource_path('stubs/'),
    

Gotchas and Tips

Pitfalls

  1. Migration Conflicts

    • If the table already exists, the generator fails silently (check .gitignore for database/migrations/).
    • Fix: Delete the migration file and regenerate or manually adjust the schema.
  2. Livewire Component Naming

    • Components are named Index, Create, Edit, Show but must match route names.
    • Fix: Ensure Index component handles GET /posts (not GET /posts/index).
  3. API vs. Web Route Duplication

    • Generates both Route::resource (web) and Route::apiResource (API) for non-API stacks.
    • Fix: Use --route flag or manually remove duplicates in routes/api.php.
  4. Tailwind/Livewire Dependencies

    • Assumes Tailwind is configured (check tailwind.config.js).
    • Fix: Run npm install and npx tailwindcss build if styles are missing.
  5. Eloquent Relationship Assumptions

    • Generates belongsTo for foreign keys but no inverse relationships (e.g., hasMany).
    • Fix: Manually add relationships post-generation.

Debugging

  • CLI Prompt Errors:
    • If prompts hang, ensure laravel/prompts is installed (composer require laravel/prompts).
  • View Rendering Issues:
    • Clear compiled views:
      php artisan view:clear
      
  • Route Conflicts:
    • Check php artisan route:list for duplicates. Use php artisan route:clear if needed.

Tips

  1. Field Validation

    • Generated FormRequest classes include basic validation (e.g., required|string).
    • Extend in app/Http/Requests:
      public function rules() {
          return [
              'title' => 'required|string|max:255',
              'body' => 'required|string',
          ];
      }
      
  2. Partial Generation

    • Skip views by using api stack, then manually create Blade files later.
  3. Relationship Handling

    • For hasMany/belongsToMany, define relationships in the model after generation:
      public function comments() {
          return $this->hasMany(Comment::class);
      }
      
  4. Testing Generated Code

    • Use Laravel’s Feature tests:
      public function test_list_posts() {
          $response = $this->get('/posts');
          $response->assertStatus(200);
      }
      
  5. Performance Optimization

    • API Controllers: Add pagination to index():
      return Post::paginate(15);
      
    • Livewire: Use wire:model.live for real-time updates.
  6. Customizing Stubs

    • Example: Modify tailwind/form.blade.php to add error messages:
      @error($field)
          <div class="text-red-500">{{ $message }}</div>
      @enderror
      
  7. Multi-Tenant Projects

    • Extend the Post model to include tenant logic:
      protected static function booted() {
          static::addGlobalScope(new TenantScope());
      }
      
  8. Soft Deletes

    • Add use SoftDeletes; to the model and regenerate:
      use Illuminate\Database\Eloquent\SoftDeletes;
      protected $dates = ['deleted_at'];
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony
spatie/flare-daemon-runtime