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

patinthehat/laravel-require

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Install the Package Run:

    composer require patinthehat/laravel-require
    

    Add the service provider to config/app.php:

    LaravelRequire\LaravelRequireServiceProvider::class,
    
  2. First Use Case Install and auto-register a package (e.g., laracasts/flash):

    php artisan require:package laracasts/flash
    
    • The command runs composer require and attempts to auto-detect and register the package’s Service Providers and Facades.

Implementation Patterns

Core Workflow

  1. Install + Register

    php artisan require:package vendor/package
    
    • Automatically runs composer require and scans for:
      • Service Providers in config/app.php (via composer.json or package.xml).
      • Facades in aliases.php (via composer.json or package.xml).
  2. Register Only

    php artisan require:package vendor/package --register-only
    
    • Skips composer require and focuses solely on auto-registering providers/aliases.
  3. Manual Fallback If auto-registration fails (e.g., non-standard package structure), manually add:

    // config/app.php
    Vendor\Package\ServiceProvider::class,
    
    // config/app.php (aliases)
    'Flash' => Vendor\Package\Facades\Flash::class,
    

Integration Tips

  • Post-Install Hooks Chain with post-install-cmd in composer.json to run custom scripts after package installation:

    {
      "scripts": {
        "post-install-cmd": [
          "php artisan require:package vendor/package"
        ]
      }
    }
    
  • CI/CD Pipelines Use --register-only in CI to avoid redundant composer require calls if the package is already installed.

  • Custom Package Detection Extend the package’s logic by publishing its config (if available) and overriding:

    php artisan vendor:publish --provider="LaravelRequire\LaravelRequireServiceProvider"
    

Gotchas and Tips

Pitfalls

  1. Composer Path Issues

    • Error: composer.phar not found.
    • Fix: Ensure composer.phar is in the project root or composer is in your PATH.
    • Workaround: Use absolute paths:
      php /path/to/composer.phar require vendor/package
      
  2. Non-Standard Package Structure

    • Error: Auto-registration fails for packages without composer.json or package.xml.
    • Fix: Manually register providers/aliases or check the package’s docs for specific setup.
  3. Duplicate Providers

    • Error: Class already exists if the package’s provider is already registered.
    • Fix: Use --register-only to skip redundant checks or manually verify config/app.php.
  4. Facade Auto-Detection Limits

    • Limitation: Only detects facades listed in composer.json under "extra.aliases" or package.xml.
    • Workaround: Manually add aliases to config/app.php if needed.

Debugging

  • Verbose Output Run with -v for detailed logs:

    php artisan require:package vendor/package -v
    

    Example output:

    [OK] Installed vendor/package via Composer.
    [OK] Auto-detected ServiceProvider: Vendor\Package\ServiceProvider.
    [OK] Auto-detected Facade: Flash => Vendor\Package\Facades\Flash.
    
  • Dry Run Test auto-registration without installing:

    php artisan require:package vendor/package --register-only --dry-run
    

Extension Points

  1. Custom Provider/Facade Detection Override the service provider’s detectProviders() or detectFacades() methods by extending:

    class CustomLaravelRequireServiceProvider extends LaravelRequireServiceProvider {
        protected function detectProviders(array $package): array {
            // Custom logic here
            return [...];
        }
    }
    

    Register your custom provider in config/app.php.

  2. Post-Registration Hooks Listen for the laravel-require.registered event in your app’s EventServiceProvider:

    protected $listen = [
        'laravel-require.registered' => [
            'App\Listeners\PostPackageRegistration',
        ],
    ];
    
  3. Skip Auto-Registration Disable auto-registration globally by setting:

    // config/laravel-require.php (if published)
    'auto_register' => false,
    

    Then manually run php artisan require:package --register-only when needed.

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.
datacore/hub-sdk
alengo/sulu-http-cache-bundle
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
imbo/imbo-coding-standard
visualbuilder/filament-lottie
servicioslineaonce/starter-kit
atomcoder/laravel-reorderable
irajul/filament-shadcn-theme
agtp/agtp-php
agtp/mod-php
centraldesktop/protobuf-php
trappistes/laravel-custom-fields
splash/sonata-admin
splash/metadata