Install the Package
composer require baks-dev/products-brand
Ensure your composer.json includes "minimum-stability": "dev" if using pre-release versions.
Publish Assets (if needed)
Run the asset installer to copy JS/CSS/images to public/:
php artisan baks:assets:install
Verify assets appear in public/vendor/baks/products-brand/.
Database Setup Run migrations to create brand-related tables:
php artisan doctrine:migrations:diff
php artisan doctrine:migrations:migrate
Load Fixtures (Optional) Populate default admin roles for brand management:
php artisan doctrine:fixtures:load --append
First Use Case: Create a Brand
Use the Brand model (likely Baks\ProductsBrand\Entity\Brand) in a controller:
use Baks\ProductsBrand\Entity\Brand;
use Baks\ProductsBrand\Repository\BrandRepository;
public function createBrand(BrandRepository $brandRepo) {
$brand = new Brand();
$brand->setName('Example Brand');
$brand->setSlug('example-brand');
$brandRepo->save($brand);
return redirect()->route('brands.index');
}
CRUD Operations
Brand entity and BrandRepository for all database interactions.$brands = $brandRepo->findAllWithPagination($page, $limit);
Asset Management
public/uploads/brands/ (or a custom path).BrandAssetService (if available) to handle uploads:
$assetService = app(Baks\ProductsBrand\Service\BrandAssetService::class);
$assetService->uploadLogo($brand, $request->file('logo'));
API Integration
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
$normalizer = new ObjectNormalizer();
$brandData = $normalizer->normalize($brand);
Event-Driven Logic
BrandCreatedEvent) to trigger side effects:
event(new BrandCreatedEvent($brand));
Form Handling
BrandType form (if provided) in controllers:
$form = $this->createForm(Baks\ProductsBrand\Form\BrandType::class, $brand);
Service Container Binding
Bind custom services in config/services.php:
'baks.products-brand' => [
'asset_path' => 'custom/uploads/brands',
],
Access via config('services.baks.products-brand.asset_path').
Custom Validation
Extend the Brand entity validator (e.g., BrandValidator) or add constraints:
use Symfony\Component\Validator\Constraints as Assert;
$brand->setSlug($request->slug);
// Add custom validation in your controller/form.
Localization Translate brand names/descriptions using Symfony’s translation system:
$brand->setName($translator->trans('brand.example'));
Testing
Use the BrandFactory (if available) for unit tests:
$brand = BrandFactory::create(['name' => 'Test Brand']);
$this->assertEquals('test-brand', $brand->getSlug());
Missing Migrations
doctrine:migrations:diff and migrate after updating the package.php artisan doctrine:migrations:rollback
php artisan doctrine:migrations:migrate
Asset Path Conflicts
public/ permissions (chmod -R 755 public/).baks:assets:install or manually copy files.Fixture Overwrites
--append flag is critical for fixtures to avoid data loss:
php artisan doctrine:fixtures:load --append
Translation Keys
translations/ files:
en:
brand:
fields:
name: "Brand Name"
PHP 8.1+ Strictness
strict_types=1 in your project.Doctrine Events
Enable SQL logging in .env:
DOCTRINE_DQL_LOGGING=true
DOCTRINE_ORM_LOGGING=true
Event Listeners Check if events are fired by adding a temporary listener:
$dispatcher->addListener(BrandEvents::BRAND_CREATED, function ($event) {
error_log('Brand created: ' . $event->getBrand()->getName());
});
Asset Loading
Verify the asset path in config/services.php matches the actual public/ structure.
Custom Brand Fields
Extend the Brand entity:
namespace App\Entity;
use Baks\ProductsBrand\Entity\Brand as BaseBrand;
class Brand extends BaseBrand {
#[ORM\Column]
private ?string $customField = null;
}
Override Templates
Copy the package’s Twig templates to resources/views/vendor/baks/products-brand/ to customize.
Add New Features
Create a custom service and bind it in config/services.php:
'baks.products-brand.services' => [
'custom_service' => App\Service\CustomBrandService::class,
],
API Resources
Extend the BrandResource (if provided) for custom API responses:
namespace App\Resources;
use Baks\ProductsBrand\Resources\BrandResource as BaseResource;
class BrandResource extends BaseResource {
public function toArray($context = [])
{
$data = parent::toArray($context);
$data['custom_field'] = $this->resource->getCustomField();
return $data;
}
}
Console Commands
Extend existing commands (e.g., BrandCommand) or create new ones in app/Console/Commands.
How can I help you explore Laravel packages today?