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

Hautelook Alice Bundle Laravel Package

bettergist/hautelook-alice-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer in a Laravel project (note: this is a Symfony bundle, but can be adapted for Laravel via bridge packages like symfony/bundle or spatie/laravel-symfony-support):

    composer require bettergist/hautelook-alice-bundle
    

    *For Laravel, ensure compatibility with FidryAliceDataFixtures (e.g., Doctrine ORM) by installing:

    composer require theofidry/alice-data-fixtures-bundle
    
  2. Configuration Publish the bundle’s config (if available) or manually define in config/alice.php:

    return [
        'fixtures' => [
            'path' => database_path('fixtures'),
            'namespace' => 'Database\\Fixtures',
        ],
        'faker_locale' => 'en_US',
    ];
    
  3. First Fixture Create a YAML fixture file (e.g., database/fixtures/users.yml):

    App\Models\User:
      user1:
        name: '<name>'
        email: '<email>'
        password: '$2y$10$...' # Use Faker for hashing
    

    Load it via Artisan (adapt for Laravel):

    php artisan alice:load --fixtures=users
    

Implementation Patterns

Workflow Integration

  1. Fixture Organization

    • Group by Feature: Use separate YAML files per feature (e.g., users.yml, posts.yml).
    • Dependencies: Define parent-child relationships in YAML:
      App\Models\Post:
        post1:
          title: '<sentence>'
          user: '@user1' # Reference existing fixture
      
  2. Dynamic Data with Faker Leverage Faker providers in fixtures:

    App\Models\Product:
      product1:
        name: '<color> <fruit>'
        price: '<randomFloat(2, 10, 100)>'
    
  3. Laravel-Specific Adaptations

    • Service Providers: Register the bundle in AppServiceProvider:
      $this->app->register(Hautelook\AliceBundle\AliceBundle::class);
      
    • Console Commands: Extend Laravel’s Artisan for custom fixture commands:
      // app/Console/Commands/LoadFixtures.php
      use Hautelook\AliceBundle\Command\LoadFixturesCommand;
      
      class LoadFixtures extends LoadFixturesCommand {
          protected function getFixtures() {
              return ['users', 'posts']; // Custom logic
          }
      }
      
  4. Testing Integration Use fixtures in PHPUnit tests:

    public function setUp(): void {
        $this->loadFixtures(['users']);
    }
    

Gotchas and Tips

Pitfalls

  1. Symfony vs. Laravel

    • ORM Mismatch: Ensure your Laravel ORM (Eloquent) is compatible with FidryAliceDataFixtures. For Eloquent, use dama/doctrine-test-bundle as a bridge or stick to Doctrine.
    • Artisan Commands: Some Symfony commands may not work out-of-the-box. Override them in Laravel’s app/Console/Kernel.php:
      protected $commands = [
          \Hautelook\AliceBundle\Command\LoadFixturesCommand::class,
      ];
      
  2. Fixture Loading Order

    • Dependencies: Always load parent fixtures (e.g., users) before child fixtures (e.g., posts). Use --fixtures flag to specify order:
      php artisan alice:load --fixtures=users,posts
      
  3. Faker Locale Issues

    • Default Locale: Override globally in config/alice.php or per fixture:
      # users.yml
      App\Models\User:
        user1:
          name: '<name{fr_FR}>' # French name
      
  4. Database Constraints

    • Foreign Keys: Disable constraints before loading (if using Doctrine):
      // In a custom command
      $connection = $this->getContainer()->get('database_connection');
      $connection->getSchemaManager()->getDatabasePlatform()->getForeignKeysSQL('your_table');
      

Debugging Tips

  1. Dry Run Use --dry-run to preview loaded data without committing:

    php artisan alice:load --fixtures=users --dry-run
    
  2. Logging Enable debug mode in config/alice.php:

    'debug' => env('APP_DEBUG', false),
    
  3. Fixture Validation Validate YAML syntax with:

    php artisan alice:validate --fixtures=users
    

Extension Points

  1. Custom Faker Providers Register new Faker providers in config/alice.php:

    'faker_providers' => [
        \YourNamespace\CustomFakerProvider::class,
    ],
    
  2. Post-Load Callbacks Use Symfony events (if supported) or Laravel’s Model::booted() to run logic after fixture load:

    // app/Models/User.php
    protected static function booted() {
        static::created(function ($user) {
            // Post-load logic
        });
    }
    
  3. Environment-Specific Fixtures Load different fixtures per environment (e.g., staging.yml, production.yml) by extending the Artisan command:

    protected function getFixtures() {
        return config('alice.fixtures.'.config('app.env'));
    }
    
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.
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
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope