F
Filament16mo ago
Jay

Configuring canAccessPanel

I am using filament 3 and the new multi panel feature. I have 2 panels, one for admin and another for user. In the User.php model, i have the following: public function canAccessPanel(Panel $panel): bool { return $this->is_admin; } This works - admins can view both the admin panel and user panel. However, a normal user cannot access the user panel due to this. How do I fix this?
15 Replies
eera.atta
eera.atta16mo ago
Hi,
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;
}
Dennis Koch
Dennis Koch16mo ago
What's not working about that?
eera.atta
eera.atta16mo ago
it's working,
Dennis Koch
Dennis Koch16mo ago
Sounded like a question not an answer. Can you maybe edit your answer and add code formatting ( #✅┊rules ). Then I can mark this as the answers.
eera.atta
eera.atta16mo ago
Sure.
Dennis Koch
Dennis Koch16mo ago
I think you used a signle backtick. Can you try with triple backticks again? 🙈
Hasith
Hasith15mo ago
When I enter the wrong credentials it gives me a 403 forbidden error page. Can I show the user some kind of message or notification rather than an error screen? 🤔 is there any way to customize this error screen?
Hasith
Hasith15mo ago
Rather than a error screen can i show a notification to the user? Like "You do not have permission to login to this panel" ? 🤔 is there any way to achive that kind of thing? @Hasnayeen
Hasnayeen
Hasnayeen15mo ago
just copy filament login page and customize this section
No description
Hasith
Hasith15mo ago
<?php

namespace App\Filament\Admin\Pages\Auth;

use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Pages\Auth\Login as BaseAuth;

class Login extends BaseAuth
{

public function form(Form $form): Form
{
return $form
->schema([
$this->getEmailFormComponent(),
$this->getPasswordFormComponent(),
$this->getRememberFormComponent(),
]);
}

}
<?php

namespace App\Filament\Admin\Pages\Auth;

use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Pages\Auth\Login as BaseAuth;

class Login extends BaseAuth
{

public function form(Form $form): Form
{
return $form
->schema([
$this->getEmailFormComponent(),
$this->getPasswordFormComponent(),
$this->getRememberFormComponent(),
]);
}

}
Now i set up the custom login page. How can i set up a validation message or notification? if $email != "some email" ?
leoblanski
leoblanski12mo ago
I have 2 panels too, User and Admin... I created 2 differents resources to the same model (User). Have you already had the problem that canAccessPanel is called just from Admin Panel ? If i put dd() inside de function, and access from both panels, just admin show the debug.
leoblanski
leoblanski12mo ago
No description
leoblanski
leoblanski12mo ago
rsrsrs... Created a new panel to compare, and I realized that I had removed for error \the "use Filament\Http\Middleware\Authenticate" from middleware. Sorry
Want results from more Discord servers?
Add your server