F
Filamentā€¢12mo ago
BKF Dev

Access to panel

Hi, How can I set a condition (based on user role for example) to deny users to access to a specific panel? thanks šŸ™‚ without using a middleware
21 Replies
BKF Dev
BKF Devā€¢12mo ago
Thanks for answer, unfortunately this is for all panels, but I need for only panel X Am I wrong ?
Patrick Boivin
Patrick Boivinā€¢12mo ago
Yes, it's for all panels. There are other options to do it per-panel. It's on the same page in the docs.
BKF Dev
BKF Devā€¢12mo ago
Could you please share it with me, sorry I didn't get it :/
Patrick Boivin
Patrick Boivinā€¢12mo ago
Let's backtrack a little bit, you have many panels, and you want to limit access for one specific pannel?
BKF Dev
BKF Devā€¢12mo ago
Yes, one or many ofc
BKF Dev
BKF Devā€¢12mo ago
I see, do you know what is an authentication guard šŸ™‚
Patrick Boivin
Patrick Boivinā€¢12mo ago
lol, yes I got that wrong
BKF Dev
BKF Devā€¢12mo ago
hhh it's okey but really I appreciate your assistance šŸ™‚
Patrick Boivin
Patrick Boivinā€¢12mo ago
1 sec If you want to go with canAccessPanel(), you can check the current panel with filament()->getCurrentPanel()
BKF Dev
BKF Devā€¢12mo ago
Yes there's a solution but not nice for me, use that function and set a loop or may be a switch
Patrick Boivin
Patrick Boivinā€¢12mo ago
Ok, it sounds like you know what you're doing. I'll be curious to know your solution when you have it, if you want to share it.
BKF Dev
BKF Devā€¢12mo ago
What I hope to see is a function on Panel, something like this ->canAccess(bool) šŸ™‚ Waiting for a filament member to assist us
darkdev0821
darkdev0821ā€¢11mo ago
Curious about this too, different panels and different user role access would be great! šŸ™‚
Emil | Emien
Emil | Emienā€¢11mo ago
I use a Middleware
class IsAdmin
{
public function handle(Request $request, Closure $next): Response
{
if (Auth::user() && !Auth::user()->is_admin) {
abort(403, 'Access denied');
}

return $next($request);
}
}
class IsAdmin
{
public function handle(Request $request, Closure $next): Response
{
if (Auth::user() && !Auth::user()->is_admin) {
abort(403, 'Access denied');
}

return $next($request);
}
}
And then added it to the middleware() on the panel.
darkdev0821
darkdev0821ā€¢11mo ago
public function canAccessPanel(Panel $panel): bool { if ($panel->isDefault()) { return $this->is_admin; } else { return true; } } what about this? and have the admin(main one as default)? would it be a light check? rather than a middleware? this won't really help on multiple pannels, but I saw in the ServiceProvider that it has a default method
BKF Dev
BKF Devā€¢11mo ago
Thanks, and yes I've already made it like that
darkdev0821
darkdev0821ā€¢11mo ago
so probably the Middleware is the best and the easiest to do thanks
Disouric
Disouricā€¢11mo ago
public function canAccessPanel(\Filament\Panel $panel): bool
{
if ($panel->getId() === "app") {
return XXX;
} else if ($panel->getId() === "production") {
return XXX;
}

return XXX;
}
public function canAccessPanel(\Filament\Panel $panel): bool
{
if ($panel->getId() === "app") {
return XXX;
} else if ($panel->getId() === "production") {
return XXX;
}

return XXX;
}
in the model ^
HL
HLā€¢11mo ago
use Filament\Http\Middleware\Authenticate;
use App\Http\Middleware\Admin;

...
$panel
...
->authMiddleware([
Authenticate::class,
Admin::class,
])
use Filament\Http\Middleware\Authenticate;
use App\Http\Middleware\Admin;

...
$panel
...
->authMiddleware([
Authenticate::class,
Admin::class,
])
This is probably the cleanest if you have the admin middleware
Want results from more Discord servers?
Add your server
More Posts
How to make row spacing narrower? tighter?Is there a simple general way for all resources index (lists) to reduce the blank space between rowsHasBrandName ConcernI came across HasBrandName when I was figuring out how the tenants can manage their 'app_name'. I Calendar instead of input field in "dateTime" searchable as individual columns.Hi, Having: ``` Tables\Columns\TextColumn::make('updated_at') ->dateTime('M j, Y H:i') ->descripuse select form component inside livewire custom formI have a form built inside a component built using tailwind. I use common select box inside form butChange in `afterStateUpdated()` hook for file uploads?I have an Image model I'm saving extra data for on upload. In v2, I got this working using the `aftExport to Excel in V3. not working Plugin. Any other way, please?I have been using v2 and in every list (index) of my customers resources they have the button to EXPsidebar margin appear when use $panel->topNavigation() with ->sidebarCollapsibleOnDesktop()I want make PR to fix it but I don't know where I should fix this issue from the layout blade file oUse LocaleSwitcher in userMenuItemsI have multilanguage content. Currently i loop over all my allowed locales and display standard linkIs there a way to load a livewire view inside a modal of an action?This is a question for standalone action. When clicking on an `Action:make()` I want to load a livewModal form for url action on panelIs there any way I could open a modal before opening a url from an action? I want to open a custom f