owner record

hi . i want to ask. how to customize the heading of login form based on panel route ? currenly im working on two panel . admin and application . i try to overide at the vendor file like this but it did'nt work . any ideas ?
No description
No description
11 Replies
Povilas K
Povilas K8mo ago
I wouldn't do it in vendor, it should be in the Login class that would override the Vendor. Also, I think the route names are not with slashes like "application/login" but with dots, "application.login". Do the dd($routeName) to check.
Vp
Vp8mo ago
Create new filament-page that extends Filament Login like below and used that login page in panel and override getHeading():
class DomainLogin extends \Filament\Pages\Auth\Login
{
public function getHeading(): string|Htmlable
{
return __('Domain Login');
}
}

// domain panel provider
return $panel
->login(DomainLogin::class)
class DomainLogin extends \Filament\Pages\Auth\Login
{
public function getHeading(): string|Htmlable
{
return __('Domain Login');
}
}

// domain panel provider
return $panel
->login(DomainLogin::class)
Do this approach for all of your panel.
Vp
Vp8mo ago
No description
Expecto Patronum
Expecto PatronumOP8mo ago
I see. So should i make a custom page and extends to login class? I see . But how to set the heading based on panel route ? Can you show example ? My code in the pic didnt work
Povilas K
Povilas K8mo ago
Yes that's how I would do that. I've added to my to-do list to write a quick tutorial but not sure when, in a couple of days
Expecto Patronum
Expecto PatronumOP8mo ago
That would be nice . A lot of technique currently im working on Project . I will refer to your website and YouTube Channel. Thanks for sharing.
Vp
Vp8mo ago
If you don't use custom login then you have to do my example approach in each and every panel. and on every panel you override default login like my example Thanks will wait for this one.. One more thing, I create a custom login that extend default login but I have to remove that canAccessPanel checking (https://github.com/filamentphp/filament/blob/3.x/packages/panels/src/Pages/Auth/Login.php#L81) otherwise it cannot redirect to different panel (except default). Hope you consider this one as well
Povilas K
Povilas K8mo ago
@Vp I've just recreated the same thing you did in my project, and it worked well without doing anything with canAccessPanel app/Filament/Auth/AdminLogin.php:
namespace App\Filament\Auth;

use Filament\Pages\Auth\Login;
use Illuminate\Contracts\Support\Htmlable;

class AdminLogin extends Login
{
public function getHeading(): string|Htmlable
{
return __('Admin Login');
}
}
namespace App\Filament\Auth;

use Filament\Pages\Auth\Login;
use Illuminate\Contracts\Support\Htmlable;

class AdminLogin extends Login
{
public function getHeading(): string|Htmlable
{
return __('Admin Login');
}
}
app/Filament/Auth/StudentLogin.php:
namespace App\Filament\Auth;

use Filament\Pages\Auth\Login;
use Illuminate\Contracts\Support\Htmlable;

class StudentLogin extends Login
{
public function getHeading(): string|Htmlable
{
return __('Student Login');
}
}
namespace App\Filament\Auth;

use Filament\Pages\Auth\Login;
use Illuminate\Contracts\Support\Htmlable;

class StudentLogin extends Login
{
public function getHeading(): string|Htmlable
{
return __('Student Login');
}
}
app/Providers/Filament/AdminPanelProvider.php:
use App\Filament\Auth\AdminLogin;

class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin')
->login(AdminLogin::class)
use App\Filament\Auth\AdminLogin;

class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin')
->login(AdminLogin::class)
app/Providers/Filament/StudentPanelProvider.php:
use App\Filament\Auth\StudentLogin;

class StudentPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->id('student')
->path('student')
->login(StudentLogin::class)
use App\Filament\Auth\StudentLogin;

class StudentPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->id('student')
->path('student')
->login(StudentLogin::class)
Vp
Vp8mo ago
Hi @PovilasKorop sorry for not explaining well, my last message was different topic, throw in this threat just in case you'd want to experiment as well. I create a full livewire components, I remove ->login() from my panels, cause I am using my livewire as login (I provide only one login page). I check it like below():
class Login extend \Filament\Pages\Auth\Login
{
protected static string $view = 'livewire.login';

public function authenticate()
{

// ... same code, not changed.

$user = Filament::auth()->user();

// I have to remove below if ()
if (
($user instanceof FilamentUser) &&
(! $user->canAccessPanel(Filament::getCurrentPanel())) // this line always false except user() 'is_admin => true' cause admin has `->default()` in panel configuration
) {
Filament::auth()->logout();

$this->throwFailureValidationException();
}

session()->regenerate();

// return app(LoginResponse::class);

if ($user->is_admin) {
return redirect('admin');
}

return redirect('app');
}
}

// user model
public function canAccessPanel(Panel $panel): bool
{
if ($panel->getId() === 'admin') {
return $this->is_admin;
}

return !$this->admin;
}
class Login extend \Filament\Pages\Auth\Login
{
protected static string $view = 'livewire.login';

public function authenticate()
{

// ... same code, not changed.

$user = Filament::auth()->user();

// I have to remove below if ()
if (
($user instanceof FilamentUser) &&
(! $user->canAccessPanel(Filament::getCurrentPanel())) // this line always false except user() 'is_admin => true' cause admin has `->default()` in panel configuration
) {
Filament::auth()->logout();

$this->throwFailureValidationException();
}

session()->regenerate();

// return app(LoginResponse::class);

if ($user->is_admin) {
return redirect('admin');
}

return redirect('app');
}
}

// user model
public function canAccessPanel(Panel $panel): bool
{
if ($panel->getId() === 'admin') {
return $this->is_admin;
}

return !$this->admin;
}
If I didn't remove if () from above then cannot login on other panel
Povilas K
Povilas K8mo ago
oh, you're using your own livewire as login... then yeah it may be a different logic and a different case, sorry don't want to dive into that one deeper ok published it as a free snippet on our Filament Examples, but it's basically the same as @Vp suggested: https://filamentexamples.com/project/multi-panels-customize-login
Expecto Patronum
Expecto PatronumOP8mo ago
Wow . Thank you so much . I dont expect this fast update from you. God bless. Okay noted . Will try this one as well. Thanks for the sharing and ideas
Want results from more Discord servers?
Add your server