> ## Documentation Index
> Fetch the complete documentation index at: https://docs.laravelshopper.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Brands

> Most e-commerce sites sell products from several manufacturers. And each supplier can be represented by a brand.

<Warning>
  This is documentation for Shopper v1, which is no longer maintained. Please refer to the [v2 docs](/v2) for the latest information.
</Warning>

Unless you make your own products, you should always register the brands of your products in Shopper.

If you sell your own products, you must at least create your company as a brand: this helps your customer find what they are looking for, and this can bring some valuable search engine points.

## Overview

The management of brands is exactly the same as the one done in most of the e-commerce website creation tools: only the name can change. It is mainly used to facilitate the navigation of customers in your catalog, as it is increasingly common to search for a specific brand.

<Frame caption="Brands">
  <img src="https://mintcdn.com/shopperlabs-ee054f5e/jlpf_1VxeBnlQtP6/images/v1/brands.png?fit=max&auto=format&n=jlpf_1VxeBnlQtP6&q=85&s=cc61f113458e7f61a6183992e7291da7" alt="Brands" width="1249" height="833" data-path="images/v1/brands.png" />
</Frame>

New brands are automatically activated and available for your online store, even if they do not contain any products yet. You must deactivate them so that they do not appear online.

### Fields

The model used is `Shopper\Framework\Models\Shop\Product\Brand`.

| Name              | Type     | Required | Notes                                                    |
| ----------------- | -------- | -------- | -------------------------------------------------------- |
| `id`              | autoinc  |          | auto                                                     |
| `name`            | string   | yes      |                                                          |
| `slug`            | string   | yes      | Unique, default value is auto generated using brand name |
| `website`         | string   | no       | Nullable                                                 |
| `description`     | longText | no       | Nullable                                                 |
| `position`        | string   | no       | Default `0`                                              |
| `is_enabled`      | boolean  | no       | Default `false`                                          |
| `seo_title`       | string   | no       | Nullable, for seo title max length is 60                 |
| `seo_description` | string   | no       | Nullable, for seo description max length is 160          |

<Tip>
  Models are customizable, and we recommend changing the **Brand** model when you configure your site.
  To change the model you need to look at the configuration file `config/shopper/system.php` at the key `models`.
</Tip>

```php theme={null}
return [
  'models' => [
    /*
    * Eloquent model should be used to retrieve your brands. Of course,
    * it is often just the "Brand" model but you may use whatever you like.
    *
    * The model you want to use as a Brand model needs to extends the
    * `\Shopper\Framework\Models\Shop\Product\Brand` model.
    */
    'brand' => \Shopper\Framework\Models\Shop\Product\Brand::class,

    /*
    * Eloquent model should be used to retrieve your categories. Of course,
    * it is often just the "Category" model but you may use whatever you like.
    *
    * The model you want to use as a Category model needs to extends the
    * `\Shopper\Framework\Models\Shop\Product\Category` model.
    */
    'category'  => \Shopper\Framework\Models\Shop\Product\Category::class,
  ]
];
```

1. Create your own model that you have to use
   ```bash theme={null}
   php artisan make:model Brand
   ```
   Once the `app/Models/Brand.php` model is created in our app folder, we will make it extend from the `Shopper\Framework\Models\Shop\Product\Brand` model available in Shopper.

2. Extend our Brand model from the Brand Shopper Model
   ```php theme={null}
   namespace App\Models;

   use Shopper\Framework\Models\Shop\Product;

   class Brand extends Product\Brand
   {
   }
   ```

3. Update `brand` key for the model on the `system.php` config file to use our new model
   ```php theme={null}
   return [
     'models' => [
       /*
       * Eloquent model should be used to retrieve your brands. Of course,
       * it is often just the "Brand" model but you may use whatever you like.
       *
       * The model you want to use as a Brand model needs to extends the
       * `\Shopper\Framework\Models\Shop\Product\Brand` model.
       */
       'brand' => \App\Models\Brand::class,

       /*
       * Eloquent model should be used to retrieve your categories. Of course,
       * it is often just the "Category" model but you may use whatever you like.
       *
       * The model you want to use as a Category model needs to extends the
       * `\Shopper\Framework\Models\Shop\Product\Category` model.
       */
       'category'  => \Shopper\Framework\Models\Shop\Product\Category::class,
     ]
   ];
   ```

### Components

Livewire components for managing brands are available in the component configuration file `config/shopper/components.php`.

```php theme={null}
use Shopper\Framework\Http\Livewire;

return [
  'livewire' => [
    'brands.browse' => Livewire\Brands\Browse::class,
    'brands.create' => Livewire\Brands\Create::class,
    'brands.edit' => Livewire\Brands\Edit::class,

    'tables.brands-table' => Livewire\Tables\BrandsTable::class,
  ];
];
```

For handling tables in Shopper, we use [Laravel Livewire Tables](https://github.com/rappasoft/laravel-livewire-tables) package by Anthony Rappa.

## Manage Brands

The brands are accessible via the Brands Menu on the left sidebar. The display page is rendered by the Livewire component `Shopper\Framework\Http\Livewire\Brands\Browse` and for the display of the brands table is the component `Shopper\Framework\Http\Livewire\Tables\BrandsTable`.

You can modify them in the component configuration file to use your own.

### Create brand

Click on the "Create" button on the brands page, and a creation form appears.

<Frame caption="Create brand">
  <img src="https://mintcdn.com/shopperlabs-ee054f5e/jlpf_1VxeBnlQtP6/images/v1/create-brand.png?fit=max&auto=format&n=jlpf_1VxeBnlQtP6&q=85&s=3951c91cbe331454400cd447591f6724" alt="Create brand" width="1243" height="711" data-path="images/v1/create-brand.png" />
</Frame>

Save your changes in order to be taken back to the brand's list. Required fields are marked with an **asterisk (\*)**

The SEO section allows you to define how your brand information should be displayed in search engines. To modify the content you click on the button "Edit SEO preview"

<Frame caption="Brand SEO">
  <img src="https://mintcdn.com/shopperlabs-ee054f5e/jlpf_1VxeBnlQtP6/images/v1/brand-seo.png?fit=max&auto=format&n=jlpf_1VxeBnlQtP6&q=85&s=de7974a5947cd03cb549a4ab4afb412c" alt="brand seo form" width="821" height="391" data-path="images/v1/brand-seo.png" />
</Frame>

By fill the data you will have a direct preview of the content.

### Delete brand

To delete, deactivate or activate brands, you need to select the brand you want to delete and then click on the "Bulk Actions" button to choose the action you want to perform.

<Frame caption="Delete brand">
  <img src="https://mintcdn.com/shopperlabs-ee054f5e/jlpf_1VxeBnlQtP6/images/v1/delete-brand.png?fit=max&auto=format&n=jlpf_1VxeBnlQtP6&q=85&s=0056434456faced59b4024aef57ff4d5" alt="delete brand" width="1230" height="456" data-path="images/v1/delete-brand.png" />
</Frame>

## Retrieve Data

Once you have your brands and you want to display them in your store, you can retrieve them this way in your controller

```php theme={null}
namespace App\Http\Controllers;

use App\Models\Brand;
use App\Models\Product;
use Carbon\Carbon;

class HomeController extends Controller
{
  public function home()
  {
    $products = Product::with('categories', 'attributes')
      ->publish()
      ->take(8)
      ->get()
      ->map(function ($product) {
        $product['is_new'] = $product->created_at
          ->addDays(8)
          ->greaterThanOrEqualTo(Carbon::now());

        return $product;
    });

    return view('home', [
      'products' =>  $products,
      'brands' => Brand::query()->get()->take(12),
    ]);
  }
}
```

<Tip>
  Knowing that your brands can be displayed on several pages and places in your store, you can create a **View Composer** ([read more about View Composer](https://laravel.com/docs/9.x/views#view-composers)).
</Tip>

* Create your brand composer undo a custom folder `app/View/Composers`

```php theme={null}
namespace App\View\Composers;

use App\Models\Brand;
use Illuminate\View\View;

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

* Then you have to add it in your **AppServiceProvider**

```php theme={null}
namespace App\Providers;

use App\View\Composers\BrandsComposer;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
  public function boot()
  {
    View::composer('partials.brands', BrandsComposer::class);
  }
}
```

And in your front-end you can browse your brands to have a display like this

<Frame caption="Brands example list">
  <img src="https://mintcdn.com/shopperlabs-ee054f5e/jlpf_1VxeBnlQtP6/images/v1/brand-lists.png?fit=max&auto=format&n=jlpf_1VxeBnlQtP6&q=85&s=dc1abb339895296cde4b2c14275708cc" alt="Brands preview list" width="1279" height="357" data-path="images/v1/brand-lists.png" />
</Frame>
