Custom Styling Panel

We make use of Laravel Tenancy and different Panels. So for example: landlord.test -> will go to AdminPanelProvider tenant.test -> will go to TenantPanelProvider We want every tenant to be able to customize their styling of their panel, with own primary color, secondary color, logo and favicon. Is it possible to make this dynamic based on the settings of this tenant and what is the best way to get this done? For example we can store the colors and images paths in the database or is this something we can use? https://filamentglow.com/trick/dynamic-color-for-panels-per-users-1837d9c6 Thanks in advance!
FilamentPHP Glow
let users select a color for the panel
7 Replies
pechtelt
pechteltOP5w ago
Was able to do it like this with creating an middleware (thanks to @Lara Zeus):
public function handle(Request $request, Closure $next): Response
{
return app(StartSession::class)
->handle($request, function ($request) use ($next) {
if (! auth()->check()) {
return $next($request);
}

FilamentColor::register([
'primary' => Color::hex($primary_color),
'secondary' => Color::hex($secondary_color),
]);

return $next($request);
});
}
public function handle(Request $request, Closure $next): Response
{
return app(StartSession::class)
->handle($request, function ($request) use ($next) {
if (! auth()->check()) {
return $next($request);
}

FilamentColor::register([
'primary' => Color::hex($primary_color),
'secondary' => Color::hex($secondary_color),
]);

return $next($request);
});
}
Does anyone got an idea if this is also possible with brandLogo & favicon?
Dennis Koch
Dennis Koch5w ago
Does anyone got an idea if this is also possible with brandLogo & favicon?
Doesn't it work? You would use Filament::getCurrentPanel()
pechtelt
pechteltOP5w ago
Thanks for your reply, this working but every user is in the same panel and filled the logo/favicon there but want to overwrite it in the same middleware as above? Or are there better options?
Dennis Koch
Dennis Koch5w ago
Sorry, I don't understand your question
pechtelt
pechteltOP5w ago
No worries and thanks for your time @Dennis Koch. I think i'm not clearly enough - i will explain a bit more: We are building an multi-tenancy application and the TenantPanel should be whitelabel. But right now i set in the TenantPanelProvider those values:
->brandLogo(asset('img/logo.svg'))
->favicon(asset('img/favicon.svg'))
->brandLogo(asset('img/logo.svg'))
->favicon(asset('img/favicon.svg'))
What i want to get done is as user1 is logging in brandLogo & favicon should show logo-user1.svg and favicon-user1.svg for example. Same for user2, etc. Basically get the styling colors (done with above example), but looking for the solution to also be able to change brandLogo and favicon based on user. So with this middleware, i'm already changing the colors based on the user that is logged in but want to know if there is also something you can do to change the brandLogo / Favicon. Like:
Filament::Register([
'brandLogo' => asset(...)
'favicon' => asset(...)
)]
Filament::Register([
'brandLogo' => asset(...)
'favicon' => asset(...)
)]
Dennis Koch
Dennis Koch5w ago
Yes. You can access the current panel in the middleware as mentioned above and then use brandLogo(). I think it should work. Anything unclear with that?
pechtelt
pechteltOP5w ago
Wow... way easier than i tought. Thank you so much, all clear! For further me's. You can create an middleware and add this:
FilamentColor::register([
'primary' => Color::hex($primary_color),
'secondary' => Color::hex($secondary_color),
]);
Filament::getCurrentPanel()->brandLogo(asset($logo));
FilamentColor::register([
'primary' => Color::hex($primary_color),
'secondary' => Color::hex($secondary_color),
]);
Filament::getCurrentPanel()->brandLogo(asset($logo));
Want results from more Discord servers?
Add your server