mirror of
https://github.com/nihonbuzz/nihonbuzz-academy.git
synced 2026-01-26 05:25:37 +07:00
first commit
This commit is contained in:
1
database/.gitignore
vendored
Normal file
1
database/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.sqlite*
|
||||
44
database/factories/UserFactory.php
Normal file
44
database/factories/UserFactory.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The current password being used by the factory.
|
||||
*/
|
||||
protected static ?string $password;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
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),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate that the model's email address should be unverified.
|
||||
*/
|
||||
public function unverified(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'email_verified_at' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
54
database/migrations/0001_01_01_000000_create_users_table.php
Normal file
54
database/migrations/0001_01_01_000000_create_users_table.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password')->nullable();
|
||||
$table->string('avatar_url')->nullable();
|
||||
$table->integer('xp_points')->default(0);
|
||||
$table->integer('current_streak')->default(0);
|
||||
$table->timestamp('last_activity_at')->nullable();
|
||||
$table->json('metadata')->nullable();
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
||||
$table->string('email')->primary();
|
||||
$table->string('token');
|
||||
$table->timestamp('created_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('sessions', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->foreignUuid('user_id')->nullable()->index();
|
||||
$table->string('ip_address', 45)->nullable();
|
||||
$table->text('user_agent')->nullable();
|
||||
$table->longText('payload');
|
||||
$table->integer('last_activity')->index();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
Schema::dropIfExists('password_reset_tokens');
|
||||
Schema::dropIfExists('sessions');
|
||||
}
|
||||
};
|
||||
35
database/migrations/0001_01_01_000001_create_cache_table.php
Normal file
35
database/migrations/0001_01_01_000001_create_cache_table.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('cache', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->mediumText('value');
|
||||
$table->integer('expiration');
|
||||
});
|
||||
|
||||
Schema::create('cache_locks', function (Blueprint $table) {
|
||||
$table->string('key')->primary();
|
||||
$table->string('owner');
|
||||
$table->integer('expiration');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('cache');
|
||||
Schema::dropIfExists('cache_locks');
|
||||
}
|
||||
};
|
||||
57
database/migrations/0001_01_01_000002_create_jobs_table.php
Normal file
57
database/migrations/0001_01_01_000002_create_jobs_table.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('queue')->index();
|
||||
$table->longText('payload');
|
||||
$table->unsignedTinyInteger('attempts');
|
||||
$table->unsignedInteger('reserved_at')->nullable();
|
||||
$table->unsignedInteger('available_at');
|
||||
$table->unsignedInteger('created_at');
|
||||
});
|
||||
|
||||
Schema::create('job_batches', function (Blueprint $table) {
|
||||
$table->string('id')->primary();
|
||||
$table->string('name');
|
||||
$table->integer('total_jobs');
|
||||
$table->integer('pending_jobs');
|
||||
$table->integer('failed_jobs');
|
||||
$table->longText('failed_job_ids');
|
||||
$table->mediumText('options')->nullable();
|
||||
$table->integer('cancelled_at')->nullable();
|
||||
$table->integer('created_at');
|
||||
$table->integer('finished_at')->nullable();
|
||||
});
|
||||
|
||||
Schema::create('failed_jobs', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uuid')->unique();
|
||||
$table->text('connection');
|
||||
$table->text('queue');
|
||||
$table->longText('payload');
|
||||
$table->longText('exception');
|
||||
$table->timestamp('failed_at')->useCurrent();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('jobs');
|
||||
Schema::dropIfExists('job_batches');
|
||||
Schema::dropIfExists('failed_jobs');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('levels', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->string('name'); // e.g., Beginner
|
||||
$table->string('code')->unique(); // e.g., N5
|
||||
$table->text('description')->nullable();
|
||||
$table->integer('order_index')->default(0);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('levels');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$teams = config('permission.teams');
|
||||
$tableNames = config('permission.table_names');
|
||||
$columnNames = config('permission.column_names');
|
||||
$pivotRole = $columnNames['role_pivot_key'] ?? 'role_id';
|
||||
$pivotPermission = $columnNames['permission_pivot_key'] ?? 'permission_id';
|
||||
|
||||
throw_if(empty($tableNames), Exception::class, 'Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.');
|
||||
throw_if($teams && empty($columnNames['team_foreign_key'] ?? null), Exception::class, 'Error: team_foreign_key on config/permission.php not loaded. Run [php artisan config:clear] and try again.');
|
||||
|
||||
Schema::create($tableNames['permissions'], static function (Blueprint $table) {
|
||||
// $table->engine('InnoDB');
|
||||
$table->uuid('id')->primary(); // permission id
|
||||
$table->string('name'); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format)
|
||||
$table->string('guard_name'); // For MyISAM use string('guard_name', 25);
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['name', 'guard_name']);
|
||||
});
|
||||
|
||||
Schema::create($tableNames['roles'], static function (Blueprint $table) use ($teams, $columnNames) {
|
||||
// $table->engine('InnoDB');
|
||||
$table->uuid('id')->primary(); // role id
|
||||
if ($teams || config('permission.testing')) { // permission.testing is a fix for sqlite testing
|
||||
$table->unsignedBigInteger($columnNames['team_foreign_key'])->nullable();
|
||||
$table->index($columnNames['team_foreign_key'], 'roles_team_foreign_key_index');
|
||||
}
|
||||
$table->string('name'); // For MyISAM use string('name', 225); // (or 166 for InnoDB with Redundant/Compact row format)
|
||||
$table->string('guard_name'); // For MyISAM use string('guard_name', 25);
|
||||
$table->timestamps();
|
||||
if ($teams || config('permission.testing')) {
|
||||
$table->unique([$columnNames['team_foreign_key'], 'name', 'guard_name']);
|
||||
} else {
|
||||
$table->unique(['name', 'guard_name']);
|
||||
}
|
||||
});
|
||||
|
||||
Schema::create($tableNames['model_has_permissions'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotPermission, $teams) {
|
||||
|
||||
$table->string('model_type');
|
||||
$table->uuid($columnNames['model_morph_key']);
|
||||
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_model_id_model_type_index');
|
||||
|
||||
$table->foreignUuid($pivotPermission)
|
||||
->references('id') // permission id
|
||||
->on($tableNames['permissions'])
|
||||
->onDelete('cascade');
|
||||
|
||||
$table->primary([$pivotPermission, $columnNames['model_morph_key'], 'model_type']);
|
||||
|
||||
});
|
||||
|
||||
Schema::create($tableNames['model_has_roles'], static function (Blueprint $table) use ($tableNames, $columnNames, $pivotRole, $teams) {
|
||||
|
||||
|
||||
$table->string('model_type');
|
||||
$table->uuid($columnNames['model_morph_key']);
|
||||
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index');
|
||||
|
||||
$table->foreignUuid($pivotRole)
|
||||
->references('id') // role id
|
||||
->on($tableNames['roles'])
|
||||
->onDelete('cascade');
|
||||
|
||||
$table->primary([$pivotRole, $columnNames['model_morph_key'], 'model_type']);
|
||||
});
|
||||
|
||||
Schema::create($tableNames['role_has_permissions'], static function (Blueprint $table) use ($tableNames, $pivotRole, $pivotPermission) {
|
||||
|
||||
|
||||
$table->foreignUuid($pivotPermission)
|
||||
->references('id') // permission id
|
||||
->on($tableNames['permissions'])
|
||||
->onDelete('cascade');
|
||||
|
||||
$table->foreignUuid($pivotRole)
|
||||
->references('id') // role id
|
||||
->on($tableNames['roles'])
|
||||
->onDelete('cascade');
|
||||
|
||||
$table->primary([$pivotPermission, $pivotRole], 'role_has_permissions_permission_id_role_id_primary');
|
||||
});
|
||||
|
||||
app('cache')
|
||||
->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null)
|
||||
->forget(config('permission.cache.key'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
$tableNames = config('permission.table_names');
|
||||
|
||||
throw_if(empty($tableNames), Exception::class, 'Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.');
|
||||
|
||||
Schema::drop($tableNames['role_has_permissions']);
|
||||
Schema::drop($tableNames['model_has_roles']);
|
||||
Schema::drop($tableNames['model_has_permissions']);
|
||||
Schema::drop($tableNames['roles']);
|
||||
Schema::drop($tableNames['permissions']);
|
||||
}
|
||||
};
|
||||
32
database/migrations/2026_01_22_225043_create_media_table.php
Normal file
32
database/migrations/2026_01_22_225043_create_media_table.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('media', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->morphs('model');
|
||||
$table->uuid()->nullable()->unique();
|
||||
$table->string('collection_name');
|
||||
$table->string('name');
|
||||
$table->string('file_name');
|
||||
$table->string('mime_type')->nullable();
|
||||
$table->string('disk');
|
||||
$table->string('conversions_disk')->nullable();
|
||||
$table->unsignedBigInteger('size');
|
||||
$table->json('manipulations');
|
||||
$table->json('custom_properties');
|
||||
$table->json('generated_conversions');
|
||||
$table->json('responsive_images');
|
||||
$table->unsignedInteger('order_column')->nullable()->index();
|
||||
|
||||
$table->nullableTimestamps();
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('courses', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('teacher_id')->constrained('users')->cascadeOnDelete();
|
||||
$table->string('title');
|
||||
$table->string('slug')->unique();
|
||||
$table->text('description')->nullable();
|
||||
$table->foreignUuid('level_id')->nullable()->constrained('levels')->nullOnDelete();
|
||||
$table->decimal('price', 10, 2)->default(0);
|
||||
$table->string('thumbnail_url')->nullable();
|
||||
$table->boolean('is_published')->default(false);
|
||||
$table->json('metadata')->nullable();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('courses');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('modules', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('course_id')->constrained('courses')->cascadeOnDelete();
|
||||
$table->string('title');
|
||||
$table->text('description')->nullable();
|
||||
$table->integer('order_index')->default(0);
|
||||
$table->boolean('is_free_preview')->default(false);
|
||||
$table->json('metadata')->nullable();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('modules');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('lessons', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('module_id')->constrained('modules')->cascadeOnDelete();
|
||||
$table->string('title');
|
||||
$table->string('slug')->unique();
|
||||
$table->string('type')->default('text'); // video, text, quiz, vocab_list
|
||||
$table->longText('content')->nullable(); // For text lessons or transcripts
|
||||
$table->string('video_url')->nullable(); // For video lessons
|
||||
$table->string('content_pdf')->nullable(); // For PDF content
|
||||
$table->integer('duration_seconds')->default(0);
|
||||
$table->boolean('is_free_preview')->default(false);
|
||||
$table->integer('order_index')->default(0);
|
||||
$table->json('metadata')->nullable();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('lessons');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('vocabularies', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->string('word'); // The main word (Kanji usually, or Kana if no Kanji)
|
||||
$table->string('reading')->nullable(); // Kana / Furigana
|
||||
$table->string('romaji')->nullable();
|
||||
$table->string('meaning_en')->nullable();
|
||||
$table->string('meaning_id')->nullable();
|
||||
$table->foreignUuid('level_id')->nullable()->constrained('levels')->nullOnDelete();
|
||||
$table->string('audio_url')->nullable();
|
||||
$table->string('type')->nullable(); // noun, verb, adjective, etc.
|
||||
$table->json('stroke_order_svg')->nullable(); // JSON for stroke animation
|
||||
$table->json('example_sentences')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('vocabularies');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('social_accounts', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('provider'); // 'google'
|
||||
$table->string('provider_id');
|
||||
$table->text('token')->nullable();
|
||||
$table->text('refresh_token')->nullable();
|
||||
$table->timestamp('expires_at')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['provider', 'provider_id']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('social_accounts');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('enrollments', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignUuid('course_id')->constrained()->cascadeOnDelete();
|
||||
$table->timestamp('enrolled_at')->nullable();
|
||||
$table->enum('status', ['active', 'completed', 'dropped'])->default('active');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('enrollments');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('user_progress', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
$table->foreignUuid('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignUuid('lesson_id')->constrained()->cascadeOnDelete();
|
||||
$table->timestamp('completed_at')->nullable();
|
||||
$table->json('metadata')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['user_id', 'lesson_id']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('user_progress');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('srs_reviews', function (Blueprint $table) {
|
||||
$table->uuid('id')->primary();
|
||||
|
||||
$table->foreignUuid('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->foreignUuid('vocabulary_id')->constrained('vocabularies')->cascadeOnDelete();
|
||||
|
||||
// SM-2 Algorithm Fields
|
||||
$table->decimal('ease_factor', 5, 2)->default(2.50); // Minimum usually 1.3
|
||||
$table->integer('interval')->default(0); // Days
|
||||
$table->integer('repetitions')->default(0); // Consecutive success count
|
||||
|
||||
$table->timestamp('next_review_at'); // When it becomes due
|
||||
$table->timestamp('last_review_at')->nullable();
|
||||
|
||||
$table->string('status')->default('new'); // new, learning, review, graduated
|
||||
|
||||
$table->timestamps();
|
||||
|
||||
// Indexes for performance (querying 'due' cards is frequent)
|
||||
$table->index(['user_id', 'next_review_at']);
|
||||
// Uniqueness: One review entry per user per vocab? Or usage log?
|
||||
// Usually SRS keeps ONE state per item. A separate "review_logs" table would track history.
|
||||
// For now, this table tracks CURRENT state.
|
||||
$table->unique(['user_id', 'vocabulary_id']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('srs_reviews');
|
||||
}
|
||||
};
|
||||
26
database/seeders/AdminUserSeeder.php
Normal file
26
database/seeders/AdminUserSeeder.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class AdminUserSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$user = \App\Models\User::firstOrCreate(
|
||||
['email' => 'admin@nihonbuzz.academy'],
|
||||
[
|
||||
'name' => 'Super Admin',
|
||||
'password' => bcrypt('password'),
|
||||
'email_verified_at' => now(),
|
||||
]
|
||||
);
|
||||
|
||||
$user->assignRole('super_admin');
|
||||
}
|
||||
}
|
||||
32
database/seeders/DatabaseSeeder.php
Normal file
32
database/seeders/DatabaseSeeder.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DatabaseSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Seed the application's database.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->call([
|
||||
RoleSeeder::class,
|
||||
PermissionSeeder::class,
|
||||
LevelSeeder::class,
|
||||
AdminUserSeeder::class,
|
||||
VocabularySeeder::class,
|
||||
TestDataSeeder::class,
|
||||
]);
|
||||
|
||||
// User::factory(10)->create();
|
||||
|
||||
// User::factory()->create([
|
||||
// 'name' => 'Test User',
|
||||
// 'email' => 'test@example.com',
|
||||
// ]);
|
||||
}
|
||||
}
|
||||
17
database/seeders/EnrollmentSeeder.php
Normal file
17
database/seeders/EnrollmentSeeder.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class EnrollmentSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
28
database/seeders/LevelSeeder.php
Normal file
28
database/seeders/LevelSeeder.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class LevelSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$levels = [
|
||||
['code' => 'BASIC', 'name' => 'Bahasa Jepang Dasar', 'order_index' => 0, 'description' => 'Level pengenalan hiragana, katakana, dan ungkapan dasar.'],
|
||||
['code' => 'N5', 'name' => 'Beginner', 'order_index' => 1, 'description' => 'The ability to understand some basic Japanese.'],
|
||||
['code' => 'N4', 'name' => 'Elementary', 'order_index' => 2, 'description' => 'The ability to understand basic Japanese.'],
|
||||
['code' => 'N3', 'name' => 'Intermediate', 'order_index' => 3, 'description' => 'The ability to understand Japanese used in everyday situations to a certain degree.'],
|
||||
['code' => 'N2', 'name' => 'Pre-Advanced', 'order_index' => 4, 'description' => 'The ability to understand Japanese used in everyday situations, and in a variety of circumstances to a certain degree.'],
|
||||
['code' => 'N1', 'name' => 'Advanced', 'order_index' => 5, 'description' => 'The ability to understand Japanese used in a variety of circumstances.'],
|
||||
];
|
||||
|
||||
foreach ($levels as $level) {
|
||||
\App\Models\Level::firstOrCreate(['code' => $level['code']], $level);
|
||||
}
|
||||
}
|
||||
}
|
||||
66
database/seeders/PermissionSeeder.php
Normal file
66
database/seeders/PermissionSeeder.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class PermissionSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// Reset cached roles and permissions
|
||||
app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();
|
||||
|
||||
// Define Permissions
|
||||
$permissions = [
|
||||
'manage courses',
|
||||
'manage modules',
|
||||
'manage lessons',
|
||||
'manage vocabularies',
|
||||
'manage students',
|
||||
'view dashboard',
|
||||
'practice srs',
|
||||
];
|
||||
|
||||
foreach ($permissions as $permissionName) {
|
||||
$permission = \App\Models\Permission::where('name', $permissionName)->where('guard_name', 'web')->first();
|
||||
if (!$permission) {
|
||||
\App\Models\Permission::create([
|
||||
'name' => $permissionName,
|
||||
'guard_name' => 'web',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$assign = function($roleName, $perms) {
|
||||
$role = \App\Models\Role::where('name', $roleName)->where('guard_name', 'web')->first();
|
||||
if ($role) {
|
||||
$role->syncPermissions($perms);
|
||||
}
|
||||
};
|
||||
|
||||
$assign('super_admin', \App\Models\Permission::all());
|
||||
$assign('admin', [
|
||||
'manage courses',
|
||||
'manage modules',
|
||||
'manage lessons',
|
||||
'manage vocabularies',
|
||||
'manage students',
|
||||
'view dashboard',
|
||||
]);
|
||||
$assign('teacher', [
|
||||
'manage courses',
|
||||
'manage modules',
|
||||
'manage lessons',
|
||||
'view dashboard',
|
||||
]);
|
||||
$assign('student', [
|
||||
'view dashboard',
|
||||
'practice srs',
|
||||
]);
|
||||
}
|
||||
}
|
||||
47
database/seeders/RoleSeeder.php
Normal file
47
database/seeders/RoleSeeder.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\Role;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class RoleSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// Reset cached roles and permissions
|
||||
app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();
|
||||
|
||||
$roles = [
|
||||
'super_admin',
|
||||
'admin',
|
||||
'editor',
|
||||
'treasurer',
|
||||
'teacher',
|
||||
'student',
|
||||
'class_leader',
|
||||
'alumni',
|
||||
];
|
||||
|
||||
$now = Carbon::now();
|
||||
|
||||
foreach ($roles as $roleName) {
|
||||
$role = Role::where('name', $roleName)->where('guard_name', 'web')->first();
|
||||
if (!$role) {
|
||||
Role::create([
|
||||
'name' => $roleName,
|
||||
'guard_name' => 'web',
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
17
database/seeders/UserProgressSeeder.php
Normal file
17
database/seeders/UserProgressSeeder.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class UserProgressSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
54
database/seeders/VocabularySeeder.php
Normal file
54
database/seeders/VocabularySeeder.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class VocabularySeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$n5 = \App\Models\Level::where('code', 'N5')->first();
|
||||
|
||||
$vocabularies = [
|
||||
[
|
||||
'word' => '私',
|
||||
'reading' => 'わたし',
|
||||
'meaning_en' => 'I, me',
|
||||
'level_id' => $n5?->id,
|
||||
],
|
||||
[
|
||||
'word' => '家',
|
||||
'reading' => 'いえ',
|
||||
'meaning_en' => 'House, home',
|
||||
'level_id' => $n5?->id,
|
||||
],
|
||||
[
|
||||
'word' => '食べる',
|
||||
'reading' => 'たべる',
|
||||
'meaning_en' => 'To eat',
|
||||
'level_id' => $n5?->id,
|
||||
],
|
||||
[
|
||||
'word' => '日本語',
|
||||
'reading' => 'にほんご',
|
||||
'meaning_en' => 'Japanese language',
|
||||
'level_id' => $n5?->id,
|
||||
],
|
||||
[
|
||||
'word' => '勉強',
|
||||
'reading' => 'べんきょう',
|
||||
'meaning_en' => 'Study',
|
||||
'level_id' => $n5?->id,
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($vocabularies as $vocab) {
|
||||
\App\Models\Vocabulary::create($vocab);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user