›
byrcsc/laravel-whitelabel · 1.x
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.
Publish and run the migration:
php artisan whitelabel:install --database
php artisan migrateSet the driver in config/whitelabel.php:
'driver' => 'database',Create the brand named by whitelabel.default before relying on fallback.
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.
$all = $brands->all(); // array<string, Brand>
$acme = $brands->find('acme'); // Brand|null
$host = $brands->findByDomain('APP.ACME.COM'); // Brand|null
$exists = $brands->has('acme'); // boolall() returns brands keyed by identifier and ordered by identifier. Domain
lookups are case-insensitive because definitions are normalized to lowercase.
$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.
$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.
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.
Successful writes dispatch BrandCreated, BrandUpdated, or BrandDeleted
after the transaction. The cache decorator invalidates the touched identifier
and domain index automatically.