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 Structure Kit Laravel Package

mehedi250/laravel-structure-kit

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps to Begin

  1. Installation

    composer require mehedi250/laravel-structure-kit
    php artisan structure:kit:install
    

    Run the installer to publish assets (config, views, and migrations).

  2. First Use Case Generate a Model + Controller + Migration + Service + Repository structure:

    php artisan structure:make Post
    

    This creates:

    • app/Models/Post.php
    • app/Http/Controllers/PostController.php
    • database/migrations/..._create_posts_table.php
    • app/Services/PostService.php
    • app/Repositories/PostRepository.php
  3. Where to Look First

    • Config: config/structure-kit.php (customize paths, templates, and defaults).
    • CLI Commands: app/Console/Kernel.php (check registered commands).
    • Templates: resources/views/structure-kit/ (customize blade templates for scaffolding).

Implementation Patterns

Core Workflows

  1. Scaffolding a Full CRUD Module

    php artisan structure:make Post --resource --api
    
    • Generates:
      • Resource Controller (PostController with index, store, show, etc.).
      • API Routes (if --api flag is used).
      • Form Requests (for validation).
      • Tests (if configured in structure-kit.php).
  2. Customizing File Paths Override defaults in config/structure-kit.php:

    'paths' => [
        'models' => 'Domain/Models',
        'services' => 'Domain/Services',
        'repositories' => 'Domain/Repositories/Eloquent',
    ],
    

    Now php artisan structure:make User places files in Domain/.

  3. Extending with Custom Templates

    • Copy default templates from vendor/mehedi250/laravel-structure-kit/resources/views/structure-kit/ to resources/views/structure-kit/.
    • Modify (e.g., service.blade.php) to add custom methods or traits.
  4. Integrating with Existing Code

    • Use --force to overwrite existing files:
      php artisan structure:make Post --force
      
    • Partial Generation: Generate only a migration:
      php artisan structure:migration Post
      
  5. UI Preview Mode

    php artisan structure:kit:preview
    
    • Access http://your-app.test/structure-kit to visually design and export your project structure before generating files.

Integration Tips

  • Seeding Data: Pair with php artisan db:seed after migration generation.
  • API Testing: Use --api flag and integrate with tools like Postman or Laravel Dusk.
  • Team Workflows:
    • Commit structure-kit.php and template overrides to version control.
    • Document custom templates in a CONTRIBUTING.md for team consistency.
  • CI/CD: Add scaffolding to your deployment pipeline for new features:
    # Example GitHub Actions step
    - run: php artisan structure:make Feature --resource
    

Gotchas and Tips

Pitfalls

  1. Namespace Conflicts

    • If custom paths use namespaces (e.g., Domain\Models), ensure autoloading is configured in composer.json:
      "autoload": {
          "psr-4": {
              "Domain\\": "app/Domain/"
          }
      }
      
    • Run composer dump-autoload after changes.
  2. Template Overrides Not Loading

    • Clear cached views:
      php artisan view:clear
      
    • Verify custom templates are in resources/views/structure-kit/ (not resources/views/).
  3. Migration Conflicts

    • Avoid regenerating migrations for existing tables. Use --force cautiously:
      php artisan structure:migration Post --force
      
    • Backup migrations before forcing updates.
  4. CLI Command Not Found

    • Ensure the service provider is registered in config/app.php:
      'providers' => [
          Mehedi250\StructureKit\StructureKitServiceProvider::class,
      ],
      
    • Republish config if missing:
      php artisan vendor:publish --provider="Mehedi250\StructureKit\StructureKitServiceProvider"
      

Debugging

  1. Enable Debug Mode Set debug to true in config/structure-kit.php to log template rendering:

    'debug' => env('STRUCTURE_KIT_DEBUG', false),
    
  2. Check Generated Files

    • Use artisan structure:make --debug to see the full file generation process.
    • Verify permissions for the target directory (e.g., storage/logs/ for logs).
  3. Common Errors

    • "Class Not Found": Run composer dump-autoload.
    • Blade Template Errors: Validate syntax in custom templates using php artisan view:clear.

Extension Points

  1. Custom Commands Extend the package by creating a new artisan command in app/Console/Commands/ that uses the kit’s generator:

    use Mehedi250\StructureKit\Generators\Generator;
    
    class CustomGeneratorCommand extends Command {
        protected $generator;
        public function __construct(Generator $generator) {
            parent::__construct();
            $this->generator = $generator;
        }
        // ...
    }
    
  2. Dynamic Templates Use Laravel’s view composers to dynamically modify templates:

    // app/Providers/StructureKitServiceProvider.php
    public function boot() {
        view()->composer('structure-kit::service', function ($view) {
            $view->with('customMethod', 'customLogic()');
        });
    }
    
  3. Hooks for Post-Generation Listen for the structure.kit.generated event to run post-processing:

    // app/Providers/EventServiceProvider.php
    protected $listen = [
        'structure.kit.generated' => [
            'App\Listeners\PostGenerateListener',
        ],
    ];
    
  4. Testing Mock the generator in PHPUnit tests:

    $this->mock(Generator::class)->shouldReceive('generate')->once();
    

Pro Tips

  • Template Snippets: Use partials (e.g., @include('structure-kit::partials/trait')) to avoid duplication.
  • Environment-Specific Config: Use structure-kit.php to switch templates per environment:
    'templates' => env('STRUCTURE_KIT_TEMPLATES', 'default'),
    
  • Git Ignore: Add generated files to .gitignore if they’re environment-specific:
    /app/Services/__generated__
    
  • Performance: Disable debug mode in production ('debug' => false).
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.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
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