›
›
›
  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

Manage database brands.

Create, replace, list, and delete brand definitions through the writable repository.

Use the database driver when brands change without a deployment. All writes go through BrandRepository and return immutable Brand objects.

1. Enable the database driver

Publish and run the migration:

php artisan whitelabel:install --database
php artisan migrate

Set the driver in config/whitelabel.php:

'driver' => 'database',

Create the brand named by whitelabel.default before relying on fallback.

2. Create a brand

use Byrcsc\Whitelabel\Contracts\BrandRepository;

$brands = app(BrandRepository::class);

$default = $brands->create('default', [
    'name' => 'Example',
    'colors' => ['primary' => '#111827'],
]);

$acme = $brands->create('acme', [
    'name' => 'Acme',
    'domain' => 'app.acme.com',
    'colors' => ['primary' => '#7c3aed'],
]);

The identifier and each non-null domain must be unique. A collision throws BrandAlreadyExists.

3. Read brands

$all = $brands->all();                 // array<string, Brand>
$acme = $brands->find('acme');         // Brand|null
$host = $brands->findByDomain('APP.ACME.COM'); // Brand|null
$exists = $brands->has('acme');        // bool

all() returns brands keyed by identifier and ordered by identifier. Domain lookups are case-insensitive because definitions are normalized to lowercase.

4. Replace a definition

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

Update replaces the stored definition. Include every value the brand should continue to own. Omitted values become fallback candidates. An absent identifier throws UnknownBrand.

5. Delete a brand

$deleted = $brands->delete('acme');

The method returns true when it removed a row and false when no row matched. Deleting the default brand is allowed by the repository, but leaves other brands without fallback until it is restored.

Database representation

SQL NULL means a key is absent and inherits. An empty string means the brand cleared that key. Empty domains are stored as null so several brands can clear their domain without colliding in the unique index.

The colors and settings columns are JSON. Logo and favicon disk/path pairs, mail fields, and fixed scalar fields use separate nullable columns.

Write events and caching

Successful writes dispatch BrandCreated, BrandUpdated, or BrandDeleted after the transaction. The cache decorator invalidates the touched identifier and domain index automatically.

What to read next

  • Events and listeners to react to management writes.
  • Cache management to clear or configure database brand caching.
  • Testing to use the included database factory.
PreviousSpatie MultitenancyNextCustom drivers and resolvers
View source

On this page

  1. 1. Enable the database driver
  2. 2. Create a brand
  3. 3. Read brands
  4. 4. Replace a definition
  5. 5. Delete a brand
  6. Database representation
  7. Write events and caching
  8. What to read next