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 4 Generators Laravel Package

xethron/laravel-4-generators

Scaffolding generators for Laravel 4. Quickly create controllers, models, migrations, views and other boilerplate from Artisan commands to speed up CRUD and app setup, reducing repetitive work and keeping projects consistent.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation

    composer require xethron/laravel-4-generators
    php artisan vendor:publish --provider="Xethron\Generators\GeneratorsServiceProvider"
    
    • Verify the config file is published to config/generators.php.
  2. First Use Case: Generate a CRUD Resource

    php artisan generate:all Post
    
    • This creates:
      • Eloquent model (app/Models/Post.php)
      • Migration (database/migrations/..._create_posts_table.php)
      • Controller (app/Http/Controllers/PostController.php)
      • Blade views (resources/views/posts/*)
      • Factory (if configured)
  3. Where to Look First

    • Artisan Commands: Run php artisan to see available generators (e.g., generate:model, generate:controller, generate:all).
    • Config: Customize paths, stubs, and naming conventions in config/generators.php.
    • Stubs: Override default templates in resources/views/vendor/generators/stubs/ (publish them first with php artisan vendor:publish --tag=generators.stubs).

Implementation Patterns

Core Workflows

  1. Rapid CRUD Scaffolding

    • Use generate:all for full-stack CRUD:
      php artisan generate:all User --fields="name,email,password"
      
    • Manually tweak views in resources/views/ post-generation.
  2. Modular Generation

    • Generate only what you need:
      php artisan generate:model Product --migration --factory
      php artisan generate:controller Product --resource
      
  3. Custom Field Handling

    • Define fields in the command or config:
      php artisan generate:model Article --fields="title,content,published_at:datetime"
      
    • Supports basic types (string, text, integer, boolean, datetime).
  4. Integration with Existing Code

    • Models: Extend generated models with custom logic:
      class Post extends \Xethron\Generators\Eloquent\Model {
          public function comments() { return $this->hasMany(Comment::class); }
      }
      
    • Controllers: Override methods in PostController:
      public function store(Request $request) {
          $validated = $request->validate(['title' => 'required|unique:posts']);
          return parent::store($validated);
      }
      
  5. Testing

    • Generate factories for testing:
      php artisan generate:factory User
      
    • Write tests against generated controllers:
      public function test_create_post() {
          $response = $this->post('/posts', ['title' => 'Test']);
          $response->assertRedirect('/posts');
      }
      

Integration Tips

  • Laravel 5+ Compatibility:

    • Use --force to overwrite files if needed:
      php artisan generate:all Post --force
      
    • For API resources, generate a controller first, then manually add ApiResource:
      php artisan generate:controller Post --api
      
  • View Customization:

    • Extend base views by creating resources/views/posts/partials/_form.blade.php.
    • Override layouts in resources/views/layouts/app.blade.php.
  • Database-Specific Features:

    • Add custom columns to migrations:
      $table->json('metadata')->nullable();
      
    • Use --table to specify an existing table:
      php artisan generate:model Post --table=blog_posts
      
  • Automation:

    • Chain commands in a script for bulk generation:
      php artisan generate:all User && php artisan generate:all Post
      

Gotchas and Tips

Pitfalls

  1. Laravel Version Mismatch

    • Issue: Last release is for Laravel 4/5.1. May break in Laravel 8+.
    • Fix: Fork the repo and update dependencies (e.g., illuminate/support).
    • Workaround: Use for Laravel 5.x only; migrate to native generators for newer versions.
  2. Outdated Stubs

    • Issue: Generated views use Bootstrap 3 and Blade syntax that may conflict with modern Laravel.
    • Fix: Override stubs in resources/views/vendor/generators/stubs/:
      php artisan vendor:publish --tag=generators.stubs
      
    • Tip: Replace @extends('app') with @extends('layouts.app') for Laravel 5.4+.
  3. No API Resource Support

    • Issue: Generates traditional controllers, not ApiResource.
    • Fix: Manually convert or use make:resource for API endpoints.
  4. Hardcoded Routes

    • Issue: Routes are defined in controllers (e.g., Route::get('posts', 'PostController@index')).
    • Fix: Use Laravel’s Route::resource() in routes/web.php post-generation.
  5. Factory Quirks

    • Issue: Factories may not support Laravel 5.5+ features (e.g., Faker changes).
    • Fix: Update factory stubs or use make:factory for new projects.
  6. No Test Generation

    • Issue: No built-in test scaffolding.
    • Fix: Manually create tests or use phpunit templates.

Debugging

  • Command Not Found:
    • Ensure the service provider is registered in config/app.php:
      'providers' => [
          Xethron\Generators\GeneratorsServiceProvider::class,
      ],
      
  • Stub Overrides Not Working:
    • Verify paths in config/generators.php:
      'stubs' => [
          'model' => resource_path('views/vendor/generators/stubs/model.stub'),
      ],
      
  • Migration Errors:
    • Check for reserved keywords (e.g., order) in field names. Use --table to specify an existing table if needed.

Configuration Quirks

  • Custom Paths:
    • Override default paths in config/generators.php:
      'paths' => [
          'models' => app_path('Domain/Models'),
          'migrations' => database_path('migrations/custom'),
      ],
      
  • Naming Conventions:
    • Customize singular/plural forms:
      'naming' => [
          'singular' => 'Post',
          'plural' => 'Posts',
      ],
      
  • Field Defaults:
    • Set defaults in config/generators.php:
      'fields' => [
          'created_at' => 'timestamp',
          'updated_at' => 'timestamp',
      ],
      

Extension Points

  1. Custom Stubs

    • Create new stubs for unique needs (e.g., model.stub, controller.stub).
    • Example: Add ApiResource support to controller stubs.
  2. Post-Generation Hooks

    • Use Laravel’s register method in GeneratorsServiceProvider to add logic after generation:
      public function register() {
          $this->app->afterResolving('generators', function ($generators) {
              // Run custom logic post-generation
          });
      }
      
  3. Command Extensions

    • Extend existing commands (e.g., GenerateAllCommand):
      class CustomGenerateAllCommand extends GenerateAllCommand {
          protected function getFields() {
              return ['title' => 'string', 'slug' => 'string'];
          }
      }
      
  4. Integration with Laravel Mix

    • Add post-generation tasks to webpack.mix.js:
      mix.postCss('resources/css/app.css', 'public/css', [
          require('postcss-import'),
      ]);
      

Pro Tips

  • Pair with Laravel Shift Generators:
    • Use xethron/laravel-4-generators for legacy projects and laravel-shift/generators for new ones.
  • Git Ignore:
    • Add generated files to .gitignore if using dynamic names:
      /resources/views/posts/*
      
  • CI/CD:
    • Automate generation in pipelines (e.g., php artisan generate:all User in deploy.sh).
  • Documentation:
    • Generate a README.md for each module:
      echo "# Post Module" > docs/posts.md && php artisan generate:all Post >> docs/posts.md
      
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