Skip to content

Commit

Permalink
feat: defined how to generate course with specially students and teacher
Browse files Browse the repository at this point in the history
Make one course has one teacher and 0-9 student during development to help us understand what do we do, this is the most important part for us.
  • Loading branch information
godruoyi committed Jan 10, 2024
1 parent 6d10dd2 commit 54f676c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
4 changes: 3 additions & 1 deletion database/factories/CourseFactory.php
Expand Up @@ -17,7 +17,9 @@ class CourseFactory extends Factory
public function definition(): array
{
return [
//
'name' => $this->faker->name,
'description' => $this->faker->text,
'content' => $this->faker->text,
];
}
}
13 changes: 11 additions & 2 deletions database/seeders/CourseSeeder.php
Expand Up @@ -2,7 +2,9 @@

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use App\Models\Course;
use App\Models\Student;
use App\Models\Teacher;
use Illuminate\Database\Seeder;

class CourseSeeder extends Seeder
Expand All @@ -12,6 +14,13 @@ class CourseSeeder extends Seeder
*/
public function run(): void
{
//
$students = Student::all();
$teachers = Teacher::all();

Course::factory()->count(10)->make()->each(function ($course) use ($students, $teachers) {
$course->teacher()->associate($teachers->random());
$course->save();
$course->students()->attach($students->random(rand(0, 9)));
});
}
}
1 change: 1 addition & 0 deletions database/seeders/DatabaseSeeder.php
Expand Up @@ -15,6 +15,7 @@ public function run(): void
$this->call([
StudentSeeder::class,
TeacherSeeder::class,
CourseSeeder::class,
]);
}
}
1 change: 0 additions & 1 deletion database/seeders/StudentSeeder.php
Expand Up @@ -3,7 +3,6 @@
namespace Database\Seeders;

use App\Models\Student;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class StudentSeeder extends Seeder
Expand Down
1 change: 0 additions & 1 deletion database/seeders/TeacherSeeder.php
Expand Up @@ -3,7 +3,6 @@
namespace Database\Seeders;

use App\Models\Teacher;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class TeacherSeeder extends Seeder
Expand Down

0 comments on commit 54f676c

Please sign in to comment.