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 Generator Laravel Package

infyomlabs/laravel-generator

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps to Begin

  1. Installation

    composer require infyomlabs/laravel-generator
    php artisan vendor:publish --provider="InfyOmLabs\Generator\GeneratorServiceProvider"
    php artisan migrate
    php artisan generator:install
    
    • Run php artisan generator:install to set up the package and initialize the database tables.
  2. First Use Case: Generate a Basic CRUD

    php artisan generator:crud User
    
    • This generates a Model, Migration, Controller, Views (Admin Panel), API Endpoints, and Routes for the User resource.
    • Access the admin panel at /admin/users (default route).
  3. Where to Look First

    • Documentation: InfyOm Official Docs (covers setup, customization, and advanced features).
    • Generator Commands:
      php artisan generator:list  # List all available generators
      php artisan generator:help   # Get help for a specific generator
      
    • Published Config: config/generator.php (adjust themes, default settings, and API responses).

Implementation Patterns

Core Workflows

  1. CRUD Generation (Admin + API)

    php artisan generator:crud Post --api --theme=adminlte
    
    • Generates:
      • Admin Panel: Blade views with CRUD operations (create, read, update, delete).
      • API: RESTful endpoints (/api/posts) with Laravel Sanctum/Passport support.
      • Validation Rules: Automatically generated in app/Generators/Requests.
      • Relationships: Supports belongsTo, hasMany, manyToMany (configured in --relationship flag).
  2. Customizing Fields

    • Use --fields to define custom fields:
      php artisan generator:crud Product --fields="name:string,price:decimal:8,2|description:text|required"
      
    • Supports field types, validation rules, and UI customizations (e.g., select, checkbox, date).
  3. Themes and Styling

    • Built-in themes: adminlte, bootstrap, material.
    • Override views in resources/views/vendor/generator/ or extend via --theme flag.
    • Example:
      php artisan generator:crud Event --theme=material --api
      
  4. API-Only Generation

    php artisan generator:api Post
    
    • Generates only API resources, controllers, and routes (no admin panel).
  5. Seeding and Testing

    • Use --seed to generate a seeder:
      php artisan generator:crud Role --seed
      
    • Automatically includes factory and seeder files in database/factories and database/seeds.
  6. Integration with Existing Code

    • Manual Overrides: Generated files are placed in app/Generators/. Modify them directly or use --force to regenerate.
    • Service Providers: Extend functionality via GeneratorServiceProvider or publish custom templates.

Advanced Patterns

  1. Dynamic Relationships

    • Generate relationships on the fly:
      php artisan generator:crud Post --relationship="author:App\Models\User:belongsTo"
      
    • Supports polymorphic, many-to-many, and custom pivot tables.
  2. Custom Actions

    • Add custom methods to controllers via --actions:
      php artisan generator:crud Order --actions="cancel,ship"
      
    • Generates routes and controller methods (e.g., cancelOrder(), shipOrder()).
  3. API Resource Customization

    • Override app/Generators/Http/Resources/ to modify API responses.
    • Example: Extend PostResource to include custom fields.
  4. Multi-Auth Support

    • Configure config/generator.php to use Sanctum, Passport, or JWT for API authentication.
  5. Localization

    • Generate localized CRUDs:
      php artisan generator:crud Product --locale=en,fr
      
    • Views and validation messages are localized by default.

Gotchas and Tips

Pitfalls and Debugging

  1. Permission Issues

    • Ensure storage/logs/laravel-generator.log has write permissions.
    • Common fix:
      chmod -R 775 storage/
      
  2. Route Conflicts

    • Admin routes are prefixed with /admin. If conflicts arise, override in routes/web.php:
      Route::prefix('custom-admin')->group(function () {
          Route::resource('posts', 'GeneratorController');
      });
      
  3. Database Migrations

    • Always run php artisan migrate after generating models with --migration.
    • Rollback with:
      php artisan migrate:rollback
      
  4. Caching Issues

    • Clear views and config cache if changes don’t reflect:
      php artisan view:clear
      php artisan config:clear
      
  5. Theme Overrides Not Working

    • Published themes are in resources/views/vendor/generator/themes/.
    • Ensure your custom theme is listed in config/generator.php under themes.

Tips for Daily Use

  1. Generator Configuration

    • Customize default settings in config/generator.php:
      'default' => [
          'theme' => 'adminlte',
          'api' => true,
          'validation' => 'strict',
      ],
      
  2. Reusing Generators

    • Save time by generating base templates for common models (e.g., User, Post).
    • Use --force to update existing generators:
      php artisan generator:crud User --force
      
  3. API Testing

    • Test API endpoints with Postman or Laravel’s php artisan tinker:
      $response = Http::post('/api/users', ['name' => 'Test']);
      $response->json();
      
  4. Extending Functionality

    • Custom Generators: Create new generators by extending InfyOmLabs\Generator\Generators\BaseGenerator.
    • Hooks: Use generator.created and generator.updated events in EventServiceProvider.
  5. Performance

    • Disable unnecessary features (e.g., --no-api) to speed up generation.
    • For large projects, generate one model at a time to avoid memory issues.
  6. Backup Generated Files

    • Store custom generators in version control (e.g., app/Generators/) to avoid losing changes during updates.
  7. Debugging Generation

    • Enable verbose output:
      php artisan generator:crud User --verbose
      
    • Check logs at storage/logs/laravel-generator.log.
  8. Theme Development

    • Extend themes by copying from vendor/infyomlabs/laravel-generator/resources/views/ to your project’s resources/views/vendor/generator/.
  9. Validation Rules

    • Override validation in app/Generators/Http/Requests/ to add custom rules:
      public function rules()
      {
          return array_merge(parent::rules(), [
              'custom_field' => 'required|unique:table_name',
          ]);
      }
      
  10. API Documentation

    • Use Laravel API Resources to auto-generate Swagger/OpenAPI docs with packages like darkaonline/l5-swagger.
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.
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium