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

Creator Laravel Package

akimmaksimov85/creator

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require akimmaksimov85/creator "dev-master"
    

    Note: The package is in dev-master; ensure your project can handle unstable dependencies.

  2. Publish Configuration

    php artisan vendor:publish --provider="Akimmaksimov85\Creator\CreatorServiceProvider"
    

    This generates a creator.php config file in config/.

  3. First Use Case: Generate a Basic Entity Register a command in routes/console.php:

    use Akimmaksimov85\Creator\Commands\GenerateEntityCommand;
    
    Artisan::command('creator:entity', GenerateEntityCommand::class);
    

    Run:

    php artisan creator:entity --name="User" --namespace="App\\Entities"
    

    Expected Output: A new User entity class with annotations, UUID, and basic CRUD methods in app/Entities/User.php.


Implementation Patterns

Workflow: Scaffold a Module

  1. Generate Domain Layer

    php artisan creator:entity --name="Post" --namespace="App\\Domain\\Posts" --with-repository
    

    Output: Post.php (entity), PostRepositoryInterface.php, and PostRepository.php.

  2. Generate Application Layer

    php artisan creator:service --name="PostService" --entity="Post" --namespace="App\\Services"
    

    Output: PostService.php with CRUD methods and dependency injection for the repository.

  3. Generate API Endpoints

    php artisan creator:controller --name="PostController" --entity="Post" --namespace="App\\Http\\Controllers"
    

    Output: PostController.php with annotated routes (e.g., #[Route('/posts')]).

  4. Generate Migrations

    php artisan creator:migration --entity="Post" --fields="title:string,content:text,createdAt:datetime"
    

    Output: A migration file with UUID and timestamp fields.


Integration Tips

  • Custom Templates: Override default templates by publishing assets:

    php artisan vendor:publish --tag="creator-templates" --provider="Akimmaksimov85\Creator\CreatorServiceProvider"
    

    Modify files in resources/views/creator/.

  • Doctrine Annotations: The package auto-generates @ORM\Entity, @ORM\Table, and @ORM\Id annotations. Extend with custom annotations in the config:

    'annotations' => [
        'use' => ['Doctrine\ORM\Mapping as ORM'],
        'custom' => ['@ORM\GeneratedValue(strategy="UUID")'],
    ],
    
  • Messenger Integration: Generated services include Messenger annotations (e.g., #[AsMessageHandler]). Configure framework.yaml for async handling:

    messenger:
        transports:
            async: '%env(MESSENGER_TRANSPORT_DSN)%'
    
  • Validation: Use --with-validation flag to auto-generate Symfony Validator constraints:

    php artisan creator:entity --name="User" --with-validation
    

    Output: Includes @Assert\NotBlank and @Assert\Email annotations.


Gotchas and Tips

Pitfalls

  1. Namespace Conflicts

    • The package assumes PSR-4 autoloading. If your composer.json has custom paths, ensure namespace flags in commands match your project structure.
    • Fix: Use absolute paths in --namespace (e.g., App\\Domain\\Posts instead of Domain/Posts).
  2. Doctrine ORM Dependency

    • The package requires Doctrine ORM (doctrine/orm:^2.8). If you’re not using Doctrine, remove the doctrine/* dependencies from composer.json and override templates to strip ORM annotations.
    • Workaround: Extend the EntityGenerator class to skip ORM-specific logic.
  3. UUID Generation

    • The package defaults to Ramsey UUID. If you’re using a different UUID library (e.g., symfony/uuid), update the config:
      'uuid' => [
          'library' => 'symfony/uuid',
          'type' => 'Symfony\\Uid\\Uuid',
      ],
      
  4. Command Registration

    • Commands are not auto-registered. Always manually add them to routes/console.php or use a package like laravel/artisan for dynamic registration.
  5. Symfony Console Dependencies

    • The package relies on Symfony Console (6.1.*). If your Laravel version is incompatible, alias the Symfony\Component\Console classes in composer.json:
      "extra": {
          "laravel": {
              "dont-discover": ["akimmaksimov85/creator"]
          }
      }
      

Debugging

  1. Verbose Output Add --verbose to commands to see generated code:

    php artisan creator:entity --name="Test" --verbose
    
  2. Template Debugging To inspect the template being used, add this to your command’s handle() method:

    \Log::info($this->getTemplateContents('entity.stub'));
    
  3. Configuration Overrides Temporarily override config in config/creator.php to test changes:

    'entity' => [
        'path' => 'custom/path',
        'stub' => 'custom/Entity.stub',
    ],
    

Extension Points

  1. Custom Generators Extend the base generator classes (e.g., EntityGenerator, ServiceGenerator) in app/Generators:

    namespace App\Generators;
    
    use Akimmaksimov85\Creator\Generators\EntityGenerator;
    
    class CustomEntityGenerator extends EntityGenerator {
        protected function getStub(): string {
            return __DIR__ . '/stubs/custom.entity.stub';
        }
    }
    

    Bind it in AppServiceProvider:

    $this->app->bind(
        \Akimmaksimov85\Creator\Contracts\EntityGenerator::class,
        \App\Generators\CustomEntityGenerator::class
    );
    
  2. Dynamic Field Generation Hook into the fields event in your AppServiceProvider:

    use Akimmaksimov85\Creator\Events\FieldsPrepared;
    
    public function boot() {
        FieldsPrepared::listen(function (FieldsPrepared $event) {
            $event->fields[] = [
                'name' => 'slug',
                'type' => 'string',
                'options' => ['unique' => true],
            ];
        });
    }
    
  3. Post-Generation Hooks Use the generation.finished event to run logic after generation:

    use Akimmaksimov85\Creator\Events\GenerationFinished;
    
    GenerationFinished::listen(function (GenerationFinished $event) {
        if ($event->type === 'entity') {
            // Run migrations, seeders, etc.
            Artisan::call('migrate');
        }
    });
    

Performance Tips

  • Cache Templates: The package caches stub templates. Clear the cache after modifying templates:
    php artisan cache:clear
    
  • Batch Generation: For bulk operations, chain commands or use a custom script to avoid Artisan overhead:
    Artisan::queue([
        'creator:entity' => ['--name' => 'User'],
        'creator:entity' => ['--name' => 'Post'],
    ]);
    
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.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle