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

Product Bundle Laravel Package

cody/product-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require cody/product-bundle
    

    Publish the bundle's configuration (if applicable):

    php artisan vendor:publish --provider="Cody\ProductBundle\ProductServiceProvider"
    
  2. Service Provider Registration Ensure the bundle is registered in config/app.php under providers:

    Cody\ProductBundle\ProductServiceProvider::class,
    
  3. First Use Case: Fetching a Product Inject the ProductService into a controller or service:

    use Cody\ProductBundle\Services\ProductService;
    
    class ProductController extends Controller
    {
        protected $productService;
    
        public function __construct(ProductService $productService)
        {
            $this->productService = $productService;
        }
    
        public function show($id)
        {
            $product = $this->productService->find($id);
            return view('products.show', compact('product'));
        }
    }
    
  4. Key Configuration Check config/product.php for default settings (e.g., API endpoints, caching, or model bindings).


Implementation Patterns

Core Workflows

  1. CRUD Operations Use the ProductService facade or injected service for common actions:

    // Create
    $product = $this->productService->create([
        'name' => 'Laptop',
        'price' => 999.99,
        'sku' => 'LP-1000'
    ]);
    
    // Update
    $this->productService->update($product->id, ['price' => 899.99]);
    
    // Delete
    $this->productService->delete($product->id);
    
  2. API Integration If the bundle includes API clients (e.g., for third-party product data), use the ProductApiClient:

    $client = app(\Cody\ProductBundle\Clients\ProductApiClient::class);
    $externalProducts = $client->fetchProducts(['category' => 'electronics']);
    
  3. Event Listeners Listen for product-related events (e.g., ProductCreated, ProductUpdated):

    // In EventServiceProvider
    protected $listen = [
        'Cody\ProductBundle\Events\ProductCreated' => [
            'App\Listeners\LogProductCreation',
        ],
    ];
    
  4. Model Bindings Bind custom models to the bundle’s base Product model:

    // In a service provider
    $this->app->bind(
        \Cody\ProductBundle\Models\Product::class,
        \App\Models\CustomProduct::class
    );
    
  5. Validation Rules Extend or override validation logic via the ProductValidator:

    $validator = app(\Cody\ProductBundle\Validators\ProductValidator::class);
    $validator->extend('custom_rule', function ($attribute, $value, $parameters) {
        // Custom logic
    });
    

Gotchas and Tips

Common Pitfalls

  1. Model Conflicts

    • If you extend the base Product model, ensure your custom model includes all required methods (e.g., getPrice(), getSku()).
    • Fix: Use trait composition or abstract classes to avoid method clashes.
  2. API Rate Limiting

    • The bundle may include API clients with default rate limits. Override these in config/product.php:
      'api' => [
          'rate_limit' => 100, // Default may be too low
          'timeout' => 30,
      ],
      
  3. Caching Quirks

    • Product data might be cached aggressively. Clear caches after updates:
      php artisan cache:clear
      php artisan view:clear
      
    • Tip: Use tags for cache invalidation:
      Cache::tags(['products'])->put('product:'.$id, $product);
      
  4. Event Dispatching

    • Events may not fire if the bundle’s service provider isn’t loaded early. Register it before your app’s providers in config/app.php.
  5. Database Migrations

    • The bundle may include migrations. If you customize the schema, run:
      php artisan migrate --path=/vendor/cody/product-bundle/database/migrations
      
    • Warning: Custom migrations may conflict with the bundle’s defaults.

Debugging Tips

  1. Enable Debug Mode Set debug to true in config/product.php to log API calls and service actions:

    'debug' => env('APP_DEBUG', false),
    
  2. Log ProductService Actions Wrap service calls in a try-catch to log errors:

    try {
        $product = $this->productService->find($id);
    } catch (\Exception $e) {
        \Log::error("Product fetch failed for ID {$id}: " . $e->getMessage());
        abort(500, 'Product not found');
    }
    
  3. Check for Deprecated Methods The bundle may use deprecated Laravel features (e.g., Route::resource syntax). Update calls if warnings appear.

Extension Points

  1. Custom Product Attributes Extend the Product model to add fields:

    class CustomProduct extends \Cody\ProductBundle\Models\Product
    {
        protected $casts = [
            'is_featured' => 'boolean',
        ];
    }
    
  2. Override API Clients Bind a custom client in a service provider:

    $this->app->bind(
        \Cody\ProductBundle\Clients\ProductApiClient::class,
        \App\Clients\CustomProductApiClient::class
    );
    
  3. Add Middleware Attach middleware to product-related routes:

    Route::middleware(['auth', 'product.cache'])->group(function () {
        Route::resource('products', ProductController::class);
    });
    
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