Add mass assignable attributes to User model and specify custom login page in AdminPanelProvider

This commit is contained in:
2025-09-22 13:35:08 +05:00
parent 8a14482c07
commit 60afe0c441
4 changed files with 88 additions and 1 deletions

View File

@@ -0,0 +1,46 @@
<?php
namespace App\Filament\Pages\Auth;
use Filament\Auth\Pages\Login as BaseLogin;
use Filament\Forms\Components\TextInput;
use Filament\Schemas\Schema;
use Illuminate\Validation\ValidationException;
class Login extends BaseLogin
{
public function form(Schema $schema): Schema
{
return $schema
->components([
$this->getLoginFormComponent(),
$this->getPasswordFormComponent(),
$this->getRememberFormComponent(),
]);
}
protected function getLoginFormComponent(): TextInput
{
return TextInput::make('login')
->label('Email or Phone Number')
->required()
->autofocus();
}
protected function getCredentialsFromFormData(array $data): array
{
$login_type = filter_var($data['login'], FILTER_VALIDATE_EMAIL) ? 'email' : 'phone_number';
return [
$login_type => $data['login'],
'password' => $data['password'],
];
}
protected function throwFailureValidationException(): never
{
throw ValidationException::withMessages([
'data.login' => __('filament-panels::auth/pages/login.messages.failed'),
]);
}
}