diff --git a/database/factories/GradeFactory.php b/database/factories/GradeFactory.php new file mode 100644 index 0000000..038ddb7 --- /dev/null +++ b/database/factories/GradeFactory.php @@ -0,0 +1,23 @@ + + */ +class GradeFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name' => 'Класс' . fake()->unique()->numberBetween(1,100) + ]; + } +} diff --git a/database/factories/LessonFactory.php b/database/factories/LessonFactory.php new file mode 100644 index 0000000..c9497d0 --- /dev/null +++ b/database/factories/LessonFactory.php @@ -0,0 +1,29 @@ + + */ +class LessonFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + $typeLessonCases = TypeLesson::cases(); + + return [ + 'name' => 'Занятие' . fake()->unique()->numberBetween(), + 'description' => fake()->text(200), + 'type' => $typeLessonCases[array_rand($typeLessonCases)], + 'lesson_date' => fake()->date(), + ]; + } +} diff --git a/database/factories/StudentFactory.php b/database/factories/StudentFactory.php new file mode 100644 index 0000000..ab1a3f7 --- /dev/null +++ b/database/factories/StudentFactory.php @@ -0,0 +1,28 @@ + + */ +class StudentFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + $faker = \Faker\Factory::create('ru_RU'); + + return [ + 'name' => $faker->firstNameMale, + 'last_name' => $faker->lastNameMale, + 'middle_name' => $faker->middleNameMale, + 'birthday' => $faker->date(), + ]; + } +} diff --git a/database/factories/SubjectFactory.php b/database/factories/SubjectFactory.php new file mode 100644 index 0000000..08c7896 --- /dev/null +++ b/database/factories/SubjectFactory.php @@ -0,0 +1,23 @@ + + */ +class SubjectFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name' => 'Предмет' . fake()->unique()->numberBetween(1, 100) + ]; + } +} diff --git a/database/factories/TeacherFactory.php b/database/factories/TeacherFactory.php new file mode 100644 index 0000000..6bc6594 --- /dev/null +++ b/database/factories/TeacherFactory.php @@ -0,0 +1,28 @@ + + */ +class TeacherFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + $faker = \Faker\Factory::create('ru_RU'); + + return [ + 'name' => $faker->firstNameMale, + 'last_name' => $faker->lastNameMale, + 'middle_name' => $faker->middleNameMale, + 'birthday' => $faker->date(), + ]; + } +} diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 584104c..496310e 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -24,7 +24,6 @@ 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'), diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index d01a0ef..1344e92 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -2,8 +2,13 @@ namespace Database\Seeders; +use App\Enums\ScoreEnum; +use App\Models\Grade; +use App\Models\Lesson; +use App\Models\Student; +use App\Models\Subject; +use App\Models\Teacher; use App\Models\User; -// use Illuminate\Database\Console\Seeds\WithoutModelEvents; use Illuminate\Database\Seeder; class DatabaseSeeder extends Seeder @@ -13,11 +18,43 @@ class DatabaseSeeder extends Seeder */ public function run(): void { - // User::factory(10)->create(); + $teachers = Teacher::factory(15)->create(); + $grades = Grade::factory(10)->create(); + $subjects = Subject::factory(10)->create(); + $scores = ScoreEnum::cases(); - User::factory()->create([ - 'name' => 'Test User', - 'email' => 'test@example.com', - ]); + $teachers->each(function ($teacher) { + $user = User::factory()->create(); + $teacher->user()->save($user); + }); + + $grades->each(function ($grade) use ($subjects, $teachers, $scores){ + $grade->subjects()->sync($subjects); + $grade->teachers()->sync($teachers); + + $students = Student::factory(10)->create([ + 'grade_id' => $grade->id, + ])->each(function ($student) use ($scores) { + $user = User::factory()->create(); + $student->user()->save($user); + }); + + $lessons = Lesson::factory(30)->create([ + 'grade_id' => $grade->id, + 'subject_id' => $grade->subjects->random()->id, + 'teacher_id' => $grade->teachers->random()->id, + ]); + + $students->each(function ($student) use ($lessons, $scores) { + $lessons->each(function ($lesson) use ($student, $scores) { + $student->lessons() + ->syncWithoutDetaching([$lesson->id => ['score' => $scores[array_rand($scores)]]]); + }); + }); + }); + + $subjects->each(function ($subject) use ($teachers) { + $subject->teachers()->sync($teachers->random(2)); + }); } }