Faza 7: White-label per tenant — logo + theme color dinamic
- spatie/laravel-medialibrary instalat (migration media table)
- filament/spatie-laravel-media-library-plugin
- Company implements HasMedia + InteractsWithMedia
- collections: 'logo' + 'favicon' (singleFile)
- getLogoUrl() / getFaviconUrl() helpers
- Settings page extins: secțiune Logo & favicon cu FileUpload
- On save: clear collection + addMedia from temp upload + cleanup tmp file
- TenantPanelProvider render hooks:
- HEAD_END: theme-color meta + favicon + CSS vars override
(--primary-50 → --primary-950 generate din hex theme_color)
- SIDEBAR_LOGO_BEFORE: afișare logo upload-uit, max-height 56px
Cum funcționează:
- Tenant uploadează logo în Settings
- La fiecare request, render hook injectează <style> cu CSS vars custom
- Filament respectă --primary-* → toate butoanele/badge-urile primesc culoarea brand
- Logo apare deasupra meniului (sidebar)
This commit is contained in:
@@ -4,10 +4,10 @@ namespace App\Models\Central;
|
||||
|
||||
use App\Models\Tenant\User;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
use Stancl\Tenancy\Database\Models\Tenant as BaseTenant;
|
||||
use Stancl\Tenancy\Contracts\TenantWithDatabase;
|
||||
use Stancl\Tenancy\Database\Concerns\HasDatabase;
|
||||
use Stancl\Tenancy\Database\Concerns\HasDomains;
|
||||
|
||||
/**
|
||||
* Tenant model — extends Stancl Tenant for compatibility with the package
|
||||
@@ -16,9 +16,9 @@ use Stancl\Tenancy\Database\Concerns\HasDomains;
|
||||
* In single-DB mode we don't use HasDatabase. Domain identification is
|
||||
* handled by our own ResolveTenant middleware (slug-based, not DNS records).
|
||||
*/
|
||||
class Company extends BaseTenant
|
||||
class Company extends BaseTenant implements HasMedia
|
||||
{
|
||||
use SoftDeletes;
|
||||
use InteractsWithMedia, SoftDeletes;
|
||||
|
||||
protected $table = 'companies';
|
||||
|
||||
@@ -78,4 +78,22 @@ class Company extends BaseTenant
|
||||
$central = config('app.central_domain') ?: 'service.mir.md';
|
||||
return "https://{$this->slug}.{$central}{$path}";
|
||||
}
|
||||
|
||||
public function registerMediaCollections(): void
|
||||
{
|
||||
$this->addMediaCollection('logo')->singleFile();
|
||||
$this->addMediaCollection('favicon')->singleFile();
|
||||
}
|
||||
|
||||
public function getLogoUrl(): ?string
|
||||
{
|
||||
$m = $this->getFirstMedia('logo');
|
||||
return $m ? $m->getUrl() : null;
|
||||
}
|
||||
|
||||
public function getFaviconUrl(): ?string
|
||||
{
|
||||
$m = $this->getFirstMedia('favicon');
|
||||
return $m ? $m->getUrl() : null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user