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

Megamarket Products Laravel Package

baks-dev/megamarket-products

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require baks-dev/megamarket baks-dev/megamarket-products
    php artisan vendor:publish --provider="BaksDev\MegamarketProducts\MegamarketProductsServiceProvider" --tag="config"
    php artisan baks:assets:install
    php artisan migrate
    
  2. First Use Case Fetch a product by ID in a controller:

    use BaksDev\MegamarketProducts\Models\Product;
    
    public function showProduct($id)
    {
        $product = Product::findOrFail($id);
        return view('products.show', compact('product'));
    }
    
  3. Key Files to Review

    • config/megamarket-products.php (Configuration)
    • app/Models/Product.php (Base model)
    • routes/megamarket-products.php (Default routes)

Implementation Patterns

Core Workflows

  1. Product Management

    • CRUD Operations: Use Eloquent methods (create(), update(), delete()) on Product model.
    • Bulk Actions:
      Product::where('category_id', 5)->update(['price' => 19.99]);
      
  2. API Integration

    • REST Endpoints: Leverage default routes or extend via Route::apiResource().
    • API Resources: Use BaksDev\MegamarketProducts\Http\Resources\ProductResource for JSON responses.
  3. Event-Driven Patterns

    • Listen to product events (e.g., ProductCreated):
      Product::created(function ($product) {
          // Send notification or log
      });
      
  4. Service Layer

    • Use BaksDev\MegamarketProducts\Services\ProductService for business logic:
      $service = app(ProductService::class);
      $product = $service->createWithValidation($request->all());
      
  5. Custom Fields

    • Extend the Product model with traits or add custom columns via migrations.

Integration Tips

  1. Megamarket Core

    • Link products to Megamarket entities (e.g., Marketplace):
      $product->marketplace()->associate($marketplace)->save();
      
  2. Media Handling

    • Use spatie/laravel-medialibrary (if supported) for product images:
      $product->addMediaFromRequest('image')->toMediaCollection('images');
      
  3. Search

    • Integrate with scout or algolia for product search:
      Product::search('query')->get();
      
  4. Localization

    • Use BaksDev\MegamarketProducts\Models\ProductTranslation for multilingual support:
      $product->translate()->set('name', 'Product Name')->save();
      

Gotchas and Tips

Pitfalls

  1. Database Schema

    • Foreign Keys: Ensure marketplace_id and category_id exist in your products table.
    • Soft Deletes: The model uses SoftDeletes; use withTrashed() for deleted records.
  2. Configuration

    • Missing Config: Run php artisan vendor:publish for config if fields are missing.
    • Default Values: Override config/megamarket-products.php for custom settings (e.g., default_currency).
  3. Performance

    • Eager Loading: Avoid N+1 queries:
      Product::with('category', 'marketplace')->get();
      
    • Caching: Cache product lists if frequently accessed:
      Cache::remember('products_list', now()->addHours(1), function () {
          return Product::all();
      });
      
  4. Testing

    • Test Groups: Run tests with --group=megamarket-products for focused testing.
    • Factories: Use ProductFactory for seeding:
      ProductFactory::new()->create();
      

Debugging Tips

  1. Logs

    • Enable debug mode in config/megamarket-products.php:
      'debug' => env('APP_DEBUG', false),
      
  2. Common Errors

    • Missing Dependencies: Ensure baks-dev/megamarket is installed.
    • Migration Issues: Rollback and re-migrate if schema conflicts arise:
      php artisan migrate:rollback
      php artisan migrate
      
  3. Extension Points

    • Model Events: Override events in a service provider:
      Product::observe(ProductObserver::class);
      
    • API Responses: Extend ProductResource:
      namespace App\Http\Resources;
      use BaksDev\MegamarketProducts\Http\Resources\ProductResource as BaseResource;
      
      class ProductResource extends BaseResource {
          public function toArray($request) {
              $array = parent::toArray($request);
              $array['custom_field'] = $this->custom_field;
              return $array;
          }
      }
      
  4. Localization Quirks

    • Fallbacks: Ensure locale is set in middleware or config for translations.
  5. Asset Installation

    • Permissions: Run php artisan baks:assets:install with proper file permissions (e.g., chmod -R 755 storage/).
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.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware