25 Replies
Use closures in the config methods:
->tenant(fn () => auth()->user() ...)
ok write on this code if (fn (): bool => auth()->user()->IS_ADMIN) {
// Include the tenant section
$panel = $panel
->tenant(Team::class)
->tenantRegistration(RegisterTeam::class)
->tenantProfile(EditTeamProfile::class);
}
please read the #✅┊rules on formatting code.
I don't know what you want
Hey @Dennis Koch I think he would like to show tenant only in one condition. But the problem is is not possible to catch auth()->user() inside AdminPanelProvider
Well, I shared some code to try.
I was trying to help, but always retorn false
public function panel(Panel $panel): Panel
{
$isManager = fn() => auth()->check() && auth()->user()->isManager();
dd($isManager());
It’s a service provider. There is no authenticated user. That’s why I said you need a closure
Sure, I see
fn (): bool => auth()->user()->is_admin this not work why
Can you show the full code? Are there any errors?
"not work" is not enough info to help
I think ,It nos possible to get this on AdminPanelProvider because it’s loaded before login
Please read my answer again. You cannot simply put a Closure inside an if statement and that's not what I proposed
ok .
how do it if ((fn (): bool => auth()->user()->is_admin)) {
// Include the tenant section
$panel = $panel
->tenant(Team::class)
->tenantRegistration(RegisterTeam::class)
->tenantProfile(EditTeamProfile::class);
}
can you help me?
Yes, I can. If you read my messages:
That's the code I sent you:
You need to pass the Closure to the config methods on the Panel object.
error @Dennis Koch
Okay, sorry. Then it's not possible to use Closures for tenant registration. Usually we support it in most places. Maybe it doesn't make sense here, because Tenancy must be enabled before HTTP middlewares.
ok how to show this ok how to show this or hidde if user is admin
I think it's not possible then.
1 - create a middleware
2 - add the middleware in the admin provider
3 - in the middleware
Leandro to the resuce. Yeah, makes sense 😅
error
Not sure why it is null.. Could you share the project on the github?
i've setup this middleware but doesn't works
if i comment
in the panel
i get
Route [filament.admin.tenant.registration] not defined.
in the panel config
and the middleware
What i want is
- tenantAdmin == true can create new team
- tenantAdmin == false can't create/edit manage team
i can hide the menu voices with
but i still can access to edit page (for example)
👍