mirror of
https://github.com/nihonbuzz/nihonbuzz-academy.git
synced 2026-01-26 13:32:07 +07:00
first commit
This commit is contained in:
113
database/seeders/TestDataSeeder.php
Normal file
113
database/seeders/TestDataSeeder.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Course;
|
||||
use App\Models\Enrollment;
|
||||
use App\Models\Level;
|
||||
use App\Models\Lesson;
|
||||
use App\Models\Module;
|
||||
use App\Models\User;
|
||||
use App\Models\UserProgress;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class TestDataSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$admin = User::where('email', 'admin@nihonbuzz.academy')->first();
|
||||
if (!$admin) return;
|
||||
|
||||
$n5 = Level::where('code', 'N5')->first();
|
||||
$basic = Level::where('code', 'BASIC')->first();
|
||||
$n4 = Level::where('code', 'N4')->first();
|
||||
|
||||
// 1. Course: Mastering JLPT N5
|
||||
$course1 = Course::updateOrCreate(
|
||||
['slug' => 'mastering-jlpt-n5'],
|
||||
[
|
||||
'title' => 'Mastering JLPT N5: Dasar Bahasa Jepang',
|
||||
'description' => 'Kursus lengkap untuk persiapan JLPT N5 dari nol.',
|
||||
'level_id' => $n5->id,
|
||||
'teacher_id' => $admin->id,
|
||||
'is_published' => true,
|
||||
'price' => 0,
|
||||
]
|
||||
);
|
||||
|
||||
$module1 = Module::updateOrCreate(
|
||||
['course_id' => $course1->id, 'title' => 'Introduction to N5'],
|
||||
['order_index' => 1]
|
||||
);
|
||||
|
||||
$lessons1 = [
|
||||
['title' => 'Selamat Datang di N5', 'slug' => 'welcome-n5', 'type' => 'video'],
|
||||
['title' => 'Struktur Menulis Jepang', 'slug' => 'writing-structure', 'type' => 'text'],
|
||||
['title' => 'Kata Ganti Orang', 'slug' => 'pronouns', 'type' => 'video'],
|
||||
];
|
||||
|
||||
foreach ($lessons1 as $index => $lessonData) {
|
||||
Lesson::updateOrCreate(
|
||||
['module_id' => $module1->id, 'slug' => $lessonData['slug']],
|
||||
['title' => $lessonData['title'], 'type' => $lessonData['type'], 'order_index' => $index + 1]
|
||||
);
|
||||
}
|
||||
|
||||
// 2. Course: Hiragana & Katakana
|
||||
$course2 = Course::updateOrCreate(
|
||||
['slug' => 'kana-mastery'],
|
||||
[
|
||||
'title' => 'Katakana & Hiragana Mastery',
|
||||
'description' => 'Kuasai cara baca dan tulis Hiragana & Katakana dalam 2 minggu.',
|
||||
'level_id' => $basic->id,
|
||||
'teacher_id' => $admin->id,
|
||||
'is_published' => true,
|
||||
'price' => 0,
|
||||
]
|
||||
);
|
||||
|
||||
$module2 = Module::updateOrCreate(
|
||||
['course_id' => $course2->id, 'title' => 'Hiragana Basics'],
|
||||
['order_index' => 1]
|
||||
);
|
||||
|
||||
$lessons2 = [
|
||||
['title' => 'Baris A-I-U-E-O', 'slug' => 'vowels-kana', 'type' => 'video'],
|
||||
['title' => 'Baris KA-KI-KU-KE-KO', 'slug' => 'ka-line', 'type' => 'video'],
|
||||
];
|
||||
|
||||
foreach ($lessons2 as $index => $lessonData) {
|
||||
Lesson::updateOrCreate(
|
||||
['module_id' => $module2->id, 'slug' => $lessonData['slug']],
|
||||
['title' => $lessonData['title'], 'type' => $lessonData['type'], 'order_index' => $index + 1]
|
||||
);
|
||||
}
|
||||
|
||||
// 3. Enroll Student
|
||||
Enrollment::updateOrCreate(
|
||||
['user_id' => $admin->id, 'course_id' => $course1->id],
|
||||
['enrolled_at' => now(), 'status' => 'active']
|
||||
);
|
||||
|
||||
Enrollment::updateOrCreate(
|
||||
['user_id' => $admin->id, 'course_id' => $course2->id],
|
||||
['enrolled_at' => now(), 'status' => 'active']
|
||||
);
|
||||
|
||||
// 4. Progress
|
||||
$lessonToComplete = Lesson::where('slug', 'welcome-n5')->first();
|
||||
if ($lessonToComplete) {
|
||||
UserProgress::updateOrCreate(
|
||||
['user_id' => $admin->id, 'lesson_id' => $lessonToComplete->id],
|
||||
['completed_at' => now()]
|
||||
);
|
||||
}
|
||||
|
||||
// 5. Update User Stats
|
||||
$admin->update([
|
||||
'xp_points' => 1250,
|
||||
'current_streak' => 5,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user