feat: Add StudentFactory and StudentSeeder for generating student data, and update DatabaseSeeder to include StudentSeeder
This commit is contained in:
parent
e2bb51561c
commit
2ab88d2931
31
database/factories/StudentFactory.php
Normal file
31
database/factories/StudentFactory.php
Normal 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(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -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@'),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@ -17,6 +17,7 @@ public function run(): void
|
||||
$this->call([
|
||||
UserSeeder::class,
|
||||
LecturerSeeder::class,
|
||||
StudentSeeder::class,
|
||||
CourseSeeder::class,
|
||||
CourseScheduleSeeder::class,
|
||||
]);
|
||||
|
||||
17
database/seeders/StudentSeeder.php
Normal file
17
database/seeders/StudentSeeder.php
Normal 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();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user