›
byrcsc/laravel-whitelabel · 1.x
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.
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.
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.
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.
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.
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.