›
›
›
  1. docs
  2. ›
  3. byrcsc/laravel-whitelabel
1.x
Browse documentationOpenClose

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • Brand definitions
  • Fallback and clearing
  • Brand resolution
  • Brand repositories

Using brands

  • Blade components
  • Mail and notifications
  • Queues
  • Spatie Multitenancy

Operations

  • Manage database brands
  • Custom drivers and resolvers
  • Events and listeners
  • Cache management

Reference

  • Configuration
  • Public API
  • Console commands
  • Testing
  • Troubleshooting

Getting started

  • Introduction
  • Installation and setup
  • Quick start

Core concepts

  • Brand definitions
  • Fallback and clearing
  • Brand resolution
  • Brand repositories

Using brands

  • Blade components
  • Mail and notifications
  • Queues
  • Spatie Multitenancy

Operations

  • Manage database brands
  • Custom drivers and resolvers
  • Events and listeners
  • Cache management

Reference

  • Configuration
  • Public API
  • Console commands
  • Testing
  • Troubleshooting

byrcsc/laravel-whitelabel · 1.x

Brand repositories.

Choose how the package loads, writes, and caches brand definitions.

A brand repository stores raw definitions and returns immutable Brand objects. Choose the config driver when brands change with application code. Choose the database driver when your application must create or update brands.

The config driver

ConfigBrandRepository reads whitelabel.brands. On the first read, it validates every definition and builds a Brand for each one. It rebuilds those objects if the config array changes.

The driver is read-only. Calling create(), update(), or delete() throws UnsupportedBrandOperation.

When at least one definition exists, the configured default identifier must exist. An empty brands array is valid and returns no brands.

The database driver

DatabaseBrandRepository stores one definition per row. It supports all methods on BrandRepository and dispatches events after successful writes.

The table has unique indexes on identifier and non-null domain. A collision throws BrandAlreadyExists. Updating an absent identifier throws UnknownBrand; deleting one returns false.

Database writes replace the whole stored definition. They do not merge the new array into the previous definition:

use Byrcsc\Whitelabel\Contracts\BrandRepository;

$brands = app(BrandRepository::class);

$brands->update('acme', [
    'name' => 'Acme Inc.',
    'colors' => ['primary' => '#6d28d9'],
]);

Any previously stored key omitted above becomes absent and falls back.

The cache decorator

With caching enabled, non-config drivers are wrapped in CachedBrandRepository. It stores definitions by identifier forever and keeps a domain-to-identifier index. Successful writes invalidate the affected brand and domain index.

all() always reads from the underlying repository. Missing identifiers are not cached.

The config driver is never wrapped because Laravel's configuration cache already covers its source.

The repository contract

Resolve the active driver through the container:

use Byrcsc\Whitelabel\Contracts\BrandRepository;

$brands = app(BrandRepository::class);

$all = $brands->all();
$brand = $brands->find('acme');
$byDomain = $brands->findByDomain('app.acme.com');
$exists = $brands->has('acme');

The contract also defines create(), update(), delete(), and flush(). Every driver validates definitions against the same schema before storing them.

What it does not expose

The database driver's BrandRecord model is internal and is never returned from the repository or facade. The public factory exists for test setup, but application code should read and write through BrandRepository.

What to read next

  • Manage database brands for complete write examples.
  • Cache management for invalidation and tenant-prefixed stores.
  • Custom drivers and resolvers to implement another repository.
PreviousBrand resolutionNextBlade components
View source

On this page

  1. The config driver
  2. The database driver
  3. The cache decorator
  4. The repository contract
  5. What it does not expose
  6. What to read next