Skip to main content
Brands represent manufacturers or labels for your products. They help customers identify and filter products from their favorite manufacturers.

Model

Shopper\Core\Models\Brand
The Brand model implements the following interfaces:
use Shopper\Core\Models\Brand;

// The model implements
- Shopper\Core\Models\Contracts\Brand
- Spatie\MediaLibrary\HasMedia

Extending the Model

namespace App\Models;

use Shopper\Core\Models\Brand as BaseBrand;

class Brand extends BaseBrand
{
    // Add your customizations here
}
Update the configuration in config/shopper/models.php:
return [
    'brand' => \App\Models\Brand::class,
];

Database Schema

ColumnTypeNullableDefaultDescription
idbigintnoautoPrimary key
namestringno-Brand name
slugstringyesautoURL-friendly identifier (unique)
websitestringyesnullBrand’s official website URL
descriptionlongtextyesnullBrand description
positionintegerno0Display order position
is_enabledbooleannofalseBrand visibility status
seo_titlestring(60)yesnullSEO meta title
seo_descriptionstring(160)yesnullSEO meta description
metadatajsonyesnullAdditional custom data
created_attimestampyesnullCreation timestamp
updated_attimestampyesnullLast update timestamp

Relationships

Products

A brand has many products:
// Get all products for a brand
$brand->products; // Collection of Product models

// Count products
$brand->products()->count();

// Get enabled products only
$brand->products()->where('is_visible', true)->get();

// With eager loading
$brands = Brand::with('products')->get();

Query Scopes

Enabled Brands

use Shopper\Core\Models\Brand;

// Get only enabled brands
Brand::query()->enabled()->get();

// Combines with other queries
Brand::query()
    ->enabled()
    ->orderBy('position')
    ->get();

Status Management

Update Status

// Enable a brand
$brand->updateStatus(true);

// Disable a brand
$brand->updateStatus(false);

// Or directly update
$brand->update(['is_enabled' => true]);

Check Status

if ($brand->is_enabled) {
    // Brand is visible on storefront
}

Media Management

Brands use Spatie Media Library for logo management:
// Add a logo
$brand->addMedia($file)->toMediaCollection('default');

// Get the logo URL
$brand->getFirstMediaUrl('default');

// Get the media object
$brand->getFirstMedia('default');

// Add from URL
$brand->addMediaFromUrl('https://example.com/logo.png')
    ->toMediaCollection('default');

Creating Brands

use Shopper\Core\Models\Brand;

$brand = Brand::query()->create([
    'name' => 'Nike',
    'slug' => 'nike', // Auto-generated if not provided
    'website' => 'https://nike.com',
    'description' => 'Just Do It',
    'is_enabled' => true,
    'position' => 1,
]);

// With SEO fields
$brand = Brand::query()->create([
    'name' => 'Adidas',
    'is_enabled' => true,
    'seo_title' => 'Adidas - Official Products',
    'seo_description' => 'Shop official Adidas products...',
]);

// Add logo after creation
$brand->addMedia($logoFile)->toMediaCollection('default');

Retrieving Brands

// Get all enabled brands
$brands = Brand::query()
    ->enabled()
    ->orderBy('position')
    ->get();

// Get brands with products
$brands = Brand::query()
    ->enabled()
    ->has('products')
    ->withCount('products')
    ->get();

// Get a specific brand by slug
$brand = Brand::query()
    ->where('slug', 'nike')
    ->with('products')
    ->firstOrFail();

// Get brands for navigation/filter
$brands = Brand::query()
    ->enabled()
    ->select(['id', 'name', 'slug'])
    ->orderBy('name')
    ->get();

Disabling Brand Feature

If you don’t need brands in your store, you can disable the feature entirely:
// config/shopper/features.php
use Shopper\Enum\FeatureState;

return [
    'brand' => FeatureState::Disabled,
    // ...
];
When disabled:
  • Brand menu item is hidden from the sidebar
  • Brand-related routes are not registered
  • Brand selection is removed from product forms

Components

Publish Livewire components to customize:
php artisan shopper:component:publish brand
This creates config/shopper/components/brand.php:
use Shopper\Livewire;

return [
    'pages' => [
        'brand-index' => Livewire\Pages\Brand\Index::class,
    ],
    'components' => [
        'slide-overs.brand-form' => Livewire\SlideOvers\BrandForm::class,
    ],
];

Using Brands in Storefront

Controller Example

namespace App\Http\Controllers;

use Shopper\Core\Models\Brand;

class BrandController extends Controller
{
    public function index()
    {
        $brands = Brand::query()
            ->enabled()
            ->withCount('products')
            ->orderBy('position')
            ->get();

        return view('brands.index', compact('brands'));
    }

    public function show(string $slug)
    {
        $brand = Brand::query()
            ->where('slug', $slug)
            ->enabled()
            ->firstOrFail();

        $products = $brand->products()
            ->where('is_visible', true)
            ->paginate(12);

        return view('brands.show', compact('brand', 'products'));
    }
}

View Composer

For brands in multiple views (header, footer, filters):
// app/View/Composers/BrandsComposer.php
namespace App\View\Composers;

use Illuminate\View\View;
use Shopper\Core\Models\Brand;

class BrandsComposer
{
    public function compose(View $view): void
    {
        $view->with('brands', Brand::query()
            ->enabled()
            ->orderBy('position')
            ->take(12)
            ->get()
        );
    }
}

// In AppServiceProvider
use Illuminate\Support\Facades\View;

public function boot(): void
{
    View::composer(['partials.brands', 'filters.brands'], BrandsComposer::class);
}

Metadata

Store additional custom data using the metadata field:
$brand->update([
    'metadata' => [
        'country_of_origin' => 'USA',
        'founded_year' => 1964,
        'social' => [
            'instagram' => '@nike',
            'twitter' => '@nike',
        ],
    ],
]);

// Access metadata
$country = $brand->metadata['country_of_origin'] ?? null;