Created
January 20, 2024 00:27
-
-
Save arifnd/284899b3bc839ca2e9338f81eb9657b3 to your computer and use it in GitHub Desktop.
Sign in with a username on the Filament login page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Providers\Filament; | |
| use App\Filament\Pages\Auth\Login; | |
| use Filament\Http\Middleware\Authenticate; | |
| use Filament\Http\Middleware\DisableBladeIconComponents; | |
| use Filament\Http\Middleware\DispatchServingFilamentEvent; | |
| use Filament\Pages; | |
| use Filament\Panel; | |
| use Filament\PanelProvider; | |
| use Filament\Support\Colors\Color; | |
| use Filament\Widgets; | |
| use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse; | |
| use Illuminate\Cookie\Middleware\EncryptCookies; | |
| use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken; | |
| use Illuminate\Routing\Middleware\SubstituteBindings; | |
| use Illuminate\Session\Middleware\AuthenticateSession; | |
| use Illuminate\Session\Middleware\StartSession; | |
| use Illuminate\View\Middleware\ShareErrorsFromSession; | |
| class AdminPanelProvider extends PanelProvider | |
| { | |
| public function panel(Panel $panel): Panel | |
| { | |
| return $panel | |
| ->default() | |
| ->id('admin') | |
| ->path('admin') | |
| ->login(Login::class) | |
| ->colors([ | |
| 'primary' => Color::Amber, | |
| ]) | |
| ->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources') | |
| ->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages') | |
| ->pages([ | |
| Pages\Dashboard::class, | |
| ]) | |
| ->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets') | |
| ->widgets([ | |
| Widgets\AccountWidget::class, | |
| Widgets\FilamentInfoWidget::class, | |
| ]) | |
| ->middleware([ | |
| EncryptCookies::class, | |
| AddQueuedCookiesToResponse::class, | |
| StartSession::class, | |
| AuthenticateSession::class, | |
| ShareErrorsFromSession::class, | |
| VerifyCsrfToken::class, | |
| SubstituteBindings::class, | |
| DisableBladeIconComponents::class, | |
| DispatchServingFilamentEvent::class, | |
| ]) | |
| ->authMiddleware([ | |
| Authenticate::class, | |
| ]); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Filament\Pages\Auth; | |
| use Filament\Forms\Components\Component; | |
| 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->getUsernameFormComponent(), | |
| $this->getPasswordFormComponent(), | |
| $this->getRememberFormComponent(), | |
| ]) | |
| ->statePath('data'); | |
| } | |
| protected function getUsernameFormComponent(): Component | |
| { | |
| return TextInput::make('username') | |
| ->required(); | |
| } | |
| protected function getCredentialsFromFormData(array $data): array | |
| { | |
| return [ | |
| 'username' => $data['username'], | |
| 'password' => $data['password'], | |
| ]; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment