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