Easier way to create Filament user during development #296
minthemiddle
started this conversation in
Ideas
Replies: 2 comments 6 replies
-
@minthemiddle The Filament user is just a normal Laravel model, there's no reason you can't use it in your factory or seeder like you would any other model.
|
Beta Was this translation helpful? Give feedback.
4 replies
-
Quick and dirty solution directly in seeder: <?php
namespace Database\Seeders;
use Filament\Commands\MakeUserCommand as FilamentMakeUserCommand;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*/
public function run(): void
{
$filamentMakeUserCommand = new FilamentMakeUserCommand();
$reflector = new \ReflectionObject($filamentMakeUserCommand);
$getUserModel = $reflector->getMethod('getUserModel');
$getUserModel->setAccessible(true);
$getUserModel->invoke($filamentMakeUserCommand)::create([
'name' => 'YOUR NAME',
'email' => '[email protected]',
'password' => Hash::make('YOUR-PASSWORD'),
]);
}
} This will get invoked when you clean your database, run migrations and seed the database, for example like this:
|
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
While developing and running
php artisan migrate:fresh
every 10 minutes to get an updated database structure, it's quite unpleasant to runphp artisan make:filament-user
and go through the full process again and again. And honestly, also answering the question "Do you want to star this repo?" gets annoying soon.Two ideas:
Or did I miss a way to programmatically create user/password for Filament?
Beta Was this translation helpful? Give feedback.
All reactions