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

Crudify Laravel Package

mr.incognito/crudify

Laravel CRUD generator for API or web apps. One Artisan command scaffolds models, migrations, controllers, form requests, API resources, routes, and optional Blade views. Supports validation rules, nullable fields, foreign keys/constraints, defaults, excludes, and delete:crud cleanup.

View on GitHub
Deep Wiki
Context7

Getting Started

To begin using mr.incognito/crudify, install the package via Composer:

composer require mr.incognito/crudify

First Use Case: Generate a basic API CRUD for a User model with two fields (name and email):

php artisan make:crud User --fields="name:string|max:255;email:string~|unique:users"

This creates:

  • Model (app/Models/User.php)
  • Migration (database/migrations/..._create_users_table.php)
  • Controller (app/Http/Controllers/Api/UserController.php)
  • Form Request (app/Http/Requests/UserRequest.php)
  • API Resource (app/Http/Resources/UserResource.php)
  • Route in routes/api.php

Where to Look First:

  • README.md for field syntax and examples.
  • app/Http/Controllers/Api/ or app/Http/Controllers/Web/ for generated controllers.
  • resources/views/ (for web CRUDs) to customize Blade templates.

Implementation Patterns

1. API CRUD Workflow

Pattern: Use for internal APIs, admin panels, or third-party integrations.

php artisan make:crud Department --fields="name:string|max:255;created_by:foreign~|constrained:users" --type=api

Integration Tips:

  • Extend the Controller: Override methods in DepartmentController for custom logic (e.g., store(), update()).
    public function store(DepartmentRequest $request) {
        $validated = $request->validated();
        $validated['created_by'] = auth()->id(); // Auto-set creator
        return parent::store($request);
    }
    
  • Custom Validation: Add rules to DepartmentRequest:
    public function rules() {
        return [
            'name' => ['required', 'max:255', 'regex:/^[A-Za-z\s]+$/'],
        ];
    }
    
  • API Resources: Extend DepartmentResource to shape responses:
    public function toArray($request) {
        return [
            'id' => $this->id,
            'name' => $this->name,
            'created_at' => $this->created_at->format('Y-m-d'),
        ];
    }
    

2. Web CRUD Workflow

Pattern: Use for admin dashboards or setup wizards.

php artisan make:crud Article --fields="title:string;content:text" --type=web

Integration Tips:

  • Customize Blade Views: Modify templates in resources/views/articles/ (e.g., add Alpine.js for interactivity).
  • Form Requests: Extend ArticleRequest for custom authorization:
    public function authorize() {
        return auth()->user()->can('manage-articles');
    }
    
  • Controller Logic: Add business rules in ArticleController:
    public function update(ArticleRequest $request, Article $article) {
        if ($article->user_id !== auth()->id()) {
            abort(403);
        }
        return parent::update($request, $article);
    }
    

3. Partial Generation

Pattern: Skip files you don’t need (e.g., exclude migrations if using an existing DB).

php artisan make:crud Settings --fields="key:string;value:text" --type=api --exclude=migration,model

Use Case: Rapidly add a controller/resource for an existing table.

4. Foreign Key Handling

Pattern: Define relationships with constraints.

php artisan make:crud Order --fields="user_id:foreign|constrained:users|onDelete:cascade;product_id:foreign|constrained:products"

Post-Generation:

  • Add relationships in the model:
    public function user() {
        return $this->belongsTo(User::class);
    }
    

5. Default Values and Nullables

Pattern: Use ~ for nullable fields and default: for defaults.

php artisan make:crud Product --fields="name:string;price:decimal~|default:0.00;is_active:boolean~|default:false"

Gotchas and Tips

Pitfalls

  1. Route Conflicts:

    • Generated routes (e.g., /api/departments) may clash with existing routes. Fix: Manually adjust routes/api.php or use route model binding in controllers.
    • Tip: Use --type=web for web routes to avoid API conflicts.
  2. Foreign Key Mismatches:

    • If the constrained table doesn’t exist, the migration fails. Fix: Generate the parent CRUD first or create the table manually.
    • Tip: Use php artisan delete:crud to clean up failed attempts.
  3. Blade Template Overrides:

    • Customizing web views requires editing files in resources/views/. Gotcha: Forgetting to clear the view cache (php artisan view:clear) after changes.
    • Tip: Use @extends and @section in custom templates to preserve layout structure.
  4. Validation Rule Conflicts:

    • Custom rules in FormRequest may override generated rules. Fix: Merge rules explicitly:
      public function rules() {
          return array_merge(parent::rules(), [
              'custom_field' => 'required|custom_rule',
          ]);
      }
      
  5. Migration Timestamps:

    • Generated migrations include created_at/updated_at. Gotcha: Adding these to an existing table may cause errors if columns already exist.
    • Tip: Exclude timestamps with --exclude=migration and write a custom migration.
  6. API Resource Caching:

    • API resources may not update if cached. Fix: Disable caching in AppServiceProvider or use Resource::withoutWrapping().

Debugging Tips

  • Check Generated Files: Verify files exist in expected locations (e.g., app/Http/Requests/).
  • Artisan Debugging: Use --verbose to see generation steps:
    php artisan make:crud User --verbose
    
  • Validation Errors: Test form requests with:
    php artisan make:request TestRequest
    
    Then manually validate:
    $request = new TestRequest(['field' => 'invalid']);
    $validator = Validator::make($request->all(), $request->rules());
    

Extension Points

  1. Custom Templates:

    • Override Blade templates by copying resources/views/vendor/crudify/ to your project’s resources/views/ directory.
    • Tip: Use @include to reuse partials.
  2. Rector for Refactoring:

    • Run composer rector to upgrade generated code to newer Laravel versions.
  3. Pest Tests:

    • Extend generated tests in tests/Feature/CrudTest.php:
      public function test_custom_logic() {
          $response = $this->post('/api/users', ['name' => 'Test']);
          $response->assertStatus(201);
      }
      
  4. Dynamic Field Generation:

    • For dynamic forms, extend the controller to handle runtime fields (not natively supported but possible with custom logic).

Configuration Quirks

  • Default Type: Omits --type=api (defaults to API). Always specify --type=web for web CRUDs to avoid confusion.
  • Exclude Flag: Use commas to separate exclusions (e.g., --exclude=model,migration).
  • Field Syntax: Ensure ~ for nullable fields and | for rules are correctly placed:
    --fields="email:string~|email:required|unique:users"
    

Pro Tips

  • Delete Safely: Use --exclude=migration when deleting CRUDs to preserve DB history.
  • Batch Generation: Generate multiple CRUDs in sequence (e.g., User, Role, Permission) for RBAC systems.
  • Document Workflow: Add a CRUD_GENERATION.md file to track excluded files or customizations per model.
  • Pair with Laravel Scout: Extend API resources to include searchable fields:
    public function toSearchableArray($search) {
        return ['name' => $this->name];
    }
    
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky