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

Public API.

Reference the supported classes, contracts, methods, events, exceptions, and publish tags.

Use this page when calling Laravel Whitelabel 1.x from your application or an extension. The classes and methods below form the package's public API.

Facade and helper

The facade is Byrcsc\Whitelabel\Facades\Whitelabel.

current(): ?Brand
isResolved(): bool
activate(Brand|string $brand): Brand
forget(): void
flush(): void
define(string $id, array $definition = []): Brand
find(string $id): ?Brand
findByDomain(string $domain): ?Brand
overridden(): ?Brand

The global helper has this effective signature:

brand(?string $key = null, mixed $default = null): mixed

With no key it returns Brand|null. With a key it reads the active brand by dot notation or returns the supplied default.

Brand

Constructor:

new Brand(
    public readonly string $id,
    array $definition,
    ?Brand $fallback = null,
)

Accessors:

get(string $key, mixed $default = null): mixed
has(string $key): bool
id(): string
name(): ?string
domain(): ?string
logo(): ?BrandAsset
favicon(): ?BrandAsset
asset(string $key): ?BrandAsset
logoUrl(): ?string
faviconUrl(): ?string
assetUrl(string $key): ?string
colors(): array
color(string $name, ?string $default = null): ?string
mailFromName(): ?string
mailFromAddress(): ?string
settings(): array
setting(string $key, mixed $default = null): mixed
definition(): array
fallback(): ?Brand
withFallback(?Brand $fallback): Brand
toArray(): array

Brand is immutable and implements Laravel's Arrayable contract.

BrandAsset and BrandDefinition

new BrandAsset(public string $path, public ?string $disk = null)

BrandAsset::fromDefinition(string|array $value): ?BrandAsset
$asset->isAbsoluteUrl(): bool
$asset->url(): string
$asset->toArray(): array
BrandDefinition::validate(string $brandId, array $definition): array
BrandDefinition::inherit(array $base, array $own): array

BrandDefinition exposes constants NAME, DOMAIN, LOGO, FAVICON, COLORS, MAIL, MAIL_FROM_NAME, MAIL_FROM_ADDRESS, SETTINGS, KEYS, and NON_INHERITED.

Repository contract and manager

Byrcsc\Whitelabel\Contracts\BrandRepository defines:

all(): array
find(string $id): ?Brand
findByDomain(string $domain): ?Brand
has(string $id): bool
create(string $id, array $definition): Brand
update(string $id, array $definition): Brand
delete(string $id): bool
flush(): void

The included implementations are ConfigBrandRepository, DatabaseBrandRepository, and CachedBrandRepository. The cache decorator adds:

inner(): BrandRepository

BrandRepositoryManager supports Laravel Manager methods driver() and extend(), plus:

getDefaultDriver(): string

ConfigBrandRepository::NAME is config and DatabaseBrandRepository::NAME is database.

Resolver and tenant contracts

interface BrandResolver
{
    public function resolve(): ?Brand;
}

interface ProvidesBrand
{
    public function brand(): ?Brand;
}

The included resolvers are OverrideResolver, TenantResolver, DomainResolver, and DefaultResolver.

When Spatie Multitenancy is installed, SwitchTenantBrandTask implements:

makeCurrent(IsTenant $tenant): void
forgetCurrent(): void

The optional EagerResolveBrand middleware exposes Laravel's standard handle(Request $request, Closure $next): Response method.

Queue, mail, view, and testing types

Add the marker trait Byrcsc\Whitelabel\Queue\BrandAware to a queued class.

The public Markdown helper methods are:

BrandedMarkdown::logoUrl(): ?string
BrandedMarkdown::name(): string
BrandedMarkdown::headingStyle(): string
BrandedMarkdown::buttonStyle(string $color): string

Styles, Logo, and Favicon expose render(): View and shouldRender(): bool. Prefer their Blade tags over constructing them. Styles::DEFAULT_PREFIX is brand.

InteractsWithBrands provides protected test helpers:

actingWithBrand(array|string $brand, string $id = 'testing'): Brand
defineBrand(string $id, array $definition = []): Brand

BrandRecord::factory() returns the public BrandRecordFactory, which exposes:

definition(): array
bare(): static
identifiedBy(string $identifier): static

Events

These events each accept and expose public readonly Brand $brand:

  • BrandActivated
  • BrandDeactivated
  • BrandCreated
  • BrandUpdated
  • BrandDeleted

Exceptions

Every package exception implements Byrcsc\Whitelabel\Exceptions\WhitelabelException:

ExceptionCondition
InvalidBrandDefinitionA definition has an unknown, null, malformed, or incorrectly typed value
UnknownBrandActivation or update names an absent brand, or config lacks its default
UnsupportedBrandOperationA write is attempted through the config driver
BrandAlreadyExistsA database identifier or domain collides
CapturedBrandMissingA queued class cannot restore its captured brand

The interface extends Throwable, so one catch handles package failures:

use Byrcsc\Whitelabel\Exceptions\WhitelabelException;

try {
    Whitelabel::activate($brandId);
} catch (WhitelabelException $exception) {
    report($exception);
}

Commands and publish tags

Byrcsc\Whitelabel\WhitelabelServiceProvider is the package service provider. The command classes are Commands\InstallCommand for whitelabel:install and Commands\ClearBrandCacheCommand for whitelabel:clear. Publish tags are whitelabel-config, whitelabel-migrations, and whitelabel-views.

BrandRecord remains an internal persistence model even though its factory is public for tests. The repository never returns it.

What to read next

  • Configuration for every supported config key.
  • Console commands for options and command output.
  • Testing for test helpers and the database factory.
PreviousConfigurationNextConsole commands
View source

On this page

  1. Facade and helper
  2. Brand
  3. BrandAsset and BrandDefinition
  4. Repository contract and manager
  5. Resolver and tenant contracts
  6. Queue, mail, view, and testing types
  7. Events
  8. Exceptions
  9. Commands and publish tags
  10. What to read next