feat: Add StudentFactory and StudentSeeder for generating student data, and update DatabaseSeeder to include StudentSeeder

This commit is contained in:
Yoga Pangestu 2026-03-11 13:07:47 +07:00
parent e2bb51561c
commit 2ab88d2931
4 changed files with 51 additions and 5 deletions

View File

@ -0,0 +1,31 @@
<?php
namespace Database\Factories;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Student>
*/
class StudentFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'user_id' => User::factory(),
'full_name' => fake()->name(),
'student_number' => fake()->unique()->numerify('##########'),
'phone_number' => fake()->phoneNumber(),
'sex' => fake()->randomElement(['male', 'female']),
'address' => fake()->address(),
'date_of_birth' => fake()->date(),
'place_of_birth' => fake()->city(),
];
}
}

View File

@ -4,7 +4,6 @@
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
@ -24,11 +23,9 @@ class UserFactory extends Factory
public function definition(): array
{
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
'username' => fake()->unique()->userName(),
'password' => static::$password ??= Hash::make('Minimal8@'),
];
}

View File

@ -17,6 +17,7 @@ public function run(): void
$this->call([
UserSeeder::class,
LecturerSeeder::class,
StudentSeeder::class,
CourseSeeder::class,
CourseScheduleSeeder::class,
]);

View File

@ -0,0 +1,17 @@
<?php
namespace Database\Seeders;
use App\Models\Student;
use Illuminate\Database\Seeder;
class StudentSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
Student::factory()->count(50)->create();
}
}