Installation
composer require ekyna/product-bundle
Add to config/app.php under providers:
Ekyna\ProductBundle\ProductBundleServiceProvider::class,
Publish the config (if available):
php artisan vendor:publish --provider="Ekyna\ProductBundle\ProductBundleServiceProvider"
First Use Case
php artisan migrate
use Ekyna\ProductBundle\Models\Product;
$product = Product::create([
'name' => 'Test Product',
'sku' => 'SKU123',
'price' => 19.99,
]);
Where to Look First
app/Models/Product.php (or equivalent) for core logic.database/migrations/ for schema details.ProductService or similar in app/Services/.CRUD Operations Use Eloquent methods directly or leverage a service layer:
// Controller example
public function store(Request $request) {
$validated = $request->validate([
'name' => 'required',
'sku' => 'required|unique:products',
'price' => 'numeric',
]);
return Product::create($validated);
}
Product Attributes
Extend the Product model to handle custom attributes:
// Add to Product model
protected $appends = ['formatted_price'];
public function getFormattedPriceAttribute() {
return '$' . number_format($this->price, 2);
}
Inventory Management Integrate with inventory systems via events:
// In Product model
protected static function booted() {
static::created(function ($product) {
event(new ProductCreated($product));
});
}
API Endpoints Use Laravel’s API resources:
// ProductResource.php
public function toArray($request) {
return [
'id' => $this->id,
'name' => $this->name,
'price' => $this->price,
'sku' => $this->sku,
];
}
Product model with custom rules.belongsToMany for categories) in the Product model.// app/Observers/ProductObserver.php
public function saving(Product $product) {
$product->slug = Str::slug($product->name);
}
Missing Documentation
Product model and migrations for clues. Check for undocumented config keys.No Default Config
TODO in the README suggests missing config options.config/product.php (if published) or hardcode in the service provider.Lack of Testing
No Events/Listeners
Product model with custom events or use Laravel’s dispatch method.products table exists).public function saved(Product $product) {
\Log::debug("Product saved: ", $product->toArray());
}
ekyna/* packages).Custom Fields
Use Laravel’s morphTo/morphWith for dynamic attributes or add a product_attributes table.
API Versioning
Override routes in routes/api.php to version endpoints:
Route::prefix('v1')->group(function () {
Route::apiResource('products', ProductController::class);
});
Localization
Add locale and translated_name fields, then use Laravel’s localization helpers.
Caching Cache product lists or details:
$products = Cache::remember('products.list', now()->addHours(1), function () {
return Product::all();
});
How can I help you explore Laravel packages today?