›
byrcsc/laravel-whitelabel · 1.x
Configure two host-based brands and render their identity in a shared layout.
Laravel Whitelabel can load brands from configuration or the database. This tutorial uses the config driver because it is the shortest path to rendering two brands. Use the database driver when customers create or edit their branding at runtime; the rendering and resolution code stays the same.
The tutorial makes one Laravel route render a different name, logo, favicon, and colour for two hosts using the default domain resolver.
Edit config/whitelabel.php:
'default' => 'default',
'brands' => [
'default' => [
'name' => 'Example',
'logo' => ['disk' => 'public', 'path' => 'brands/default/logo.svg'],
'favicon' => ['disk' => 'public', 'path' => 'brands/default/favicon.svg'],
'colors' => ['primary' => '#111827'],
],
'acme' => [
'name' => 'Acme',
'domain' => 'acme.test',
'logo' => ['disk' => 'public', 'path' => 'brands/acme/logo.svg'],
'colors' => ['primary' => '#7c3aed'],
],
],acme omits its favicon, so it inherits the default favicon. Domains never
inherit because one host must identify no more than one brand.
Store these files on the disk named by each definition:
storage/app/public/brands/default/logo.svg
storage/app/public/brands/default/favicon.svg
storage/app/public/brands/acme/logo.svgIf the public disk is not linked yet, create its link:
php artisan storage:linkThe package builds asset URLs. It does not upload these files or check whether they exist.
Add the components and helper to a Blade layout:
<!doctype html>
<html lang="en">
<head>
<x-whitelabel::favicon />
<x-whitelabel::styles />
</head>
<body>
<header>
<x-whitelabel::logo class="h-8" />
<span>{{ brand('name') }}</span>
</header>
<main style="color: var(--brand-primary)">
{{ $slot }}
</main>
</body>
</html>The first call to a helper or component resolves the brand. A request for
acme.test selects acme. An unclaimed host reaches the final default resolver
and selects default.
Add an application-specific value to a definition:
'settings' => [
'support_url' => 'https://support.acme.test',
],Read it with dot notation:
<a href="{{ brand('settings.support_url') }}">Support</a>Pass a default for a setting that may not exist:
{{ brand('settings.tagline', 'Welcome') }}Point acme.test at your local application and open it. The page uses Acme's
name, logo, and primary colour with the default favicon. Open the same route on
an unclaimed local host to see the default brand.