Filament V3 - How to fill login automatically (local environment)

Filament V3 - How to fill login automatically (local environment)

·

1 min read

You're reading this, so you want the Login page ready to go in local environments, without having to type in a default user (configured in your seeder). Let's go.

Let's create a Filament Page. Press <enter> for an empty answer, when asked if the page is for a resource.

# Create the page
php artisan make:filament-page Auth/Login

# Remove the generated page view - we won't need it
rm resources/views/filament/pages/auth/login.blade.php

Head to the Login.php page, and have this code inside. We will use the base Login page, and add the extra functionality of filling the form in the local environment.

Of course, adapt the credentials to the ones in your seeder.

<?php

namespace App\Filament\Pages\Auth;

use Filament\Pages\Auth\Login as BasePage;

class Login extends BasePage
{
    public function mount(): void
    {
        parent::mount();

        if (app()->environment('local')) {
            $this->form->fill([
                'email' => 'test@example.com',
                'password' => 'password',
                'remember' => true,
            ]);
        }
    }
}

Next, let's go to the ServiceProvider of your panel. On a fresh install, this will be app/Providers/Filament/AdminPanelProvider.php .

Find the login() method, and add the Page as the argument. Find below a guide for that.

//(...)
    ->login(\App\Filament\Pages\Auth\Login::class)
//(...)

That's it! When you visit the Login page, it will be automatically filled!

Happy coding, enjoy!