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
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'));
}
Key Files to Review
config/megamarket-products.php (Configuration)app/Models/Product.php (Base model)routes/megamarket-products.php (Default routes)Product Management
create(), update(), delete()) on Product model.Product::where('category_id', 5)->update(['price' => 19.99]);
API Integration
Route::apiResource().BaksDev\MegamarketProducts\Http\Resources\ProductResource for JSON responses.Event-Driven Patterns
ProductCreated):
Product::created(function ($product) {
// Send notification or log
});
Service Layer
BaksDev\MegamarketProducts\Services\ProductService for business logic:
$service = app(ProductService::class);
$product = $service->createWithValidation($request->all());
Custom Fields
Product model with traits or add custom columns via migrations.Megamarket Core
Marketplace):
$product->marketplace()->associate($marketplace)->save();
Media Handling
spatie/laravel-medialibrary (if supported) for product images:
$product->addMediaFromRequest('image')->toMediaCollection('images');
Search
scout or algolia for product search:
Product::search('query')->get();
Localization
BaksDev\MegamarketProducts\Models\ProductTranslation for multilingual support:
$product->translate()->set('name', 'Product Name')->save();
Database Schema
marketplace_id and category_id exist in your products table.SoftDeletes; use withTrashed() for deleted records.Configuration
php artisan vendor:publish for config if fields are missing.config/megamarket-products.php for custom settings (e.g., default_currency).Performance
Product::with('category', 'marketplace')->get();
Cache::remember('products_list', now()->addHours(1), function () {
return Product::all();
});
Testing
--group=megamarket-products for focused testing.ProductFactory for seeding:
ProductFactory::new()->create();
Logs
config/megamarket-products.php:
'debug' => env('APP_DEBUG', false),
Common Errors
baks-dev/megamarket is installed.php artisan migrate:rollback
php artisan migrate
Extension Points
Product::observe(ProductObserver::class);
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;
}
}
Localization Quirks
locale is set in middleware or config for translations.Asset Installation
php artisan baks:assets:install with proper file permissions (e.g., chmod -R 755 storage/).
How can I help you explore Laravel packages today?