diff --git a/src/Middleware/SetTenant.php b/src/Middleware/SetTenant.php index e7f0cf1..2951e8c 100644 --- a/src/Middleware/SetTenant.php +++ b/src/Middleware/SetTenant.php @@ -5,8 +5,8 @@ use Closure; use Filament\Support\Colors\Color; use Filament\Support\Facades\FilamentColor; -use Illuminate\Database\Eloquent\Model; use Illuminate\Http\Request; +use LaraZeus\Tartarus\Models\Company; use Symfony\Component\HttpFoundation\Response; class SetTenant @@ -32,17 +32,19 @@ public function handle(Request $request, Closure $next): Response return $next($request); } - private function setPanelConfiguration(Model $tenant): void + private function setPanelConfiguration(Company $tenant): void { - $colorName = str($tenant->primary_color ?? 'Blue')->title(); - $color = constant("Filament\Support\Colors\Color::$colorName"); - FilamentColor::register([ - 'primary' => $color, - 'secondary' => Color::Amber, - 'danger' => Color::Red, - 'info' => Color::Blue, - 'success' => Color::Green, - 'warning' => Color::Yellow, - ]); + if ($tenant->primary_color !== null) { + $colorName = str($tenant->primary_color)->title(); + $color = constant("Filament\Support\Colors\Color::$colorName"); + FilamentColor::register([ + 'primary' => $color, + 'secondary' => Color::Amber, + 'danger' => Color::Red, + 'info' => Color::Blue, + 'success' => Color::Green, + 'warning' => Color::Yellow, + ]); + } } } diff --git a/src/Models/Company.php b/src/Models/Company.php index 77e40a3..db22412 100644 --- a/src/Models/Company.php +++ b/src/Models/Company.php @@ -32,6 +32,7 @@ class Company extends Model implements HasAvatar, HasCurrentTenantLabel, HasName public function getTenantId(): ?string { + // @phpstan-ignore-next-line return auth()->user()?->company_id; } @@ -133,9 +134,12 @@ protected function defaultProfilePhotoUrl(): string return mb_substr($segment, 0, 1); })->join(' ')); - $colorName = str(tenant()->primary_color ?? 'Blue')->title(); - $color = constant("Filament\Support\Colors\Color::$colorName"); - $bgColor = str(Rgb::fromString('rgb(' . $color[500] . ')')->toHex())->replace('#', ''); + $bgColor = 'BFA577'; + if (tenant()->primary_color !== null) { + $colorName = str(tenant()->primary_color)->title(); + $color = constant("Filament\Support\Colors\Color::$colorName"); + $bgColor = str(Rgb::fromString('rgb(' . $color[500] . ')')->toHex())->replace('#', ''); + } return sprintf('https://ui-avatars.com/api/?name=%s&color=FFFFFF&background=' . $bgColor, urlencode($name)); }