MIF_E31222307/database/factories/UserFactory.php

50 lines
1.3 KiB
PHP

<?php
namespace Database\Factories;
use App\Models\User;
use App\Models\Role; // Make sure to import the Role model
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
*/
class UserFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = User::class;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => $this->faker->name(),
'email' => $this->faker->unique()->safeEmail(),
'no_telp' => $this->faker->phoneNumber(),
'email_verified_at' => now(),
'password' => bcrypt('password'), // Or use bcrypt($this->faker->password())
'remember_token' => Str::random(10),
'role_id' => Role::factory(), // Generate a role via the Role factory
];
}
/**
* Indicate that the model's email address should be unverified.
*/
public function unverified(): static
{
return $this->state(fn (array $attributes) => [
'email_verified_at' => null,
]);
}
}