Compare commits

..

3 Commits

  1. 25
      app/Models/Category.php
  2. 50
      app/Models/Exercise.php
  3. 18
      app/Models/ExerciseQuestion.php
  4. 23
      app/Models/Media.php
  5. 51
      app/Models/Question.php
  6. 24
      app/Models/QuestionBlank.php
  7. 27
      app/Models/QuestionChoice.php
  8. 33
      app/Models/QuestionGroup.php
  9. 24
      app/Models/QuestionType.php
  10. 23
      app/Models/Skill.php
  11. 10
      app/Models/Subject.php
  12. 25
      database/migrations/2025_06_26_035409_create_se_subjects_table.php
  13. 25
      database/migrations/2025_06_26_035709_create_se_categories_table.php
  14. 24
      database/migrations/2025_06_26_035807_create_se_skills_table.php
  15. 25
      database/migrations/2025_06_26_035826_create_se_question_types_table.php
  16. 27
      database/migrations/2025_06_26_035908_create_se_media_table.php
  17. 33
      database/migrations/2025_06_26_035927_create_se_exercises_table.php
  18. 32
      database/migrations/2025_06_26_040018_create_se_question_groups_table.php
  19. 34
      database/migrations/2025_06_26_040033_create_se_questions_table.php
  20. 27
      database/migrations/2025_06_26_040054_create_se_exercise_questions_table.php
  21. 32
      database/migrations/2025_06_26_040122_create_se_question_choices_table.php
  22. 25
      database/migrations/2025_06_26_040136_create_se_question_blanks_table.php

@ -0,0 +1,25 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Category extends Model
{
use SoftDeletes;
protected $table = 'se_categories';
protected $fillable = [
'content',
'content_vi',
'description',
'status',
];
public function exercises()
{
return $this->hasMany(Exercise::class, 'category_id');
}
}

@ -0,0 +1,50 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Exercise extends Model
{
use SoftDeletes;
protected $table = 'se_exercises';
protected $fillable = [
'subject_id',
'lesson_name',
'description',
'level',
'avatar',
'status',
'category_id',
'skill_id',
'year',
'media_object_id',
];
public function subject()
{
return $this->belongsTo(Subject::class, 'subject_id');
}
public function category()
{
return $this->belongsTo(Category::class, 'category_id');
}
public function skill()
{
return $this->belongsTo(Skill::class, 'skill_id');
}
public function questionGroups()
{
return $this->hasMany(QuestionGroup::class, 'exercise_id');
}
public function questions()
{
return $this->hasMany(Question::class, 'exercise_id');
}
}

@ -0,0 +1,18 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class ExerciseQuestion extends Model
{
use SoftDeletes;
protected $table = 'se_exercise_questions';
protected $fillable = [
'exercise_id',
'question_id',
'position',
];
}

@ -0,0 +1,23 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Media extends Model
{
use SoftDeletes;
protected $table = 'se_media';
protected $fillable = [
'object_id',
'file_name',
'file_url',
'mime_type',
'size_bytes',
'position',
];
// Gợi ý: nếu cần polymorphic, bạn sẽ thay bằng morphTo()
}

@ -0,0 +1,51 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Question extends Model
{
use SoftDeletes;
protected $table = 'se_questions';
protected $fillable = [
'exercise_id',
'content',
'description',
'group_id',
'question_type_id',
'level',
'score',
'answer',
'explanation',
'hint',
'media_object_id',
];
public function exercise()
{
return $this->belongsTo(Exercise::class, 'exercise_id');
}
public function group()
{
return $this->belongsTo(QuestionGroup::class, 'group_id');
}
public function type()
{
return $this->belongsTo(QuestionType::class, 'question_type_id');
}
public function choices()
{
return $this->hasMany(QuestionChoice::class, 'question_id');
}
public function blanks()
{
return $this->hasMany(QuestionBlank::class, 'question_id');
}
}

@ -0,0 +1,24 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class QuestionBlank extends Model
{
use SoftDeletes;
protected $table = 'se_question_blanks';
protected $fillable = [
'question_id',
'position',
'correct_answer',
'other_answers',
];
public function question()
{
return $this->belongsTo(Question::class, 'question_id');
}
}

@ -0,0 +1,27 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class QuestionChoice extends Model
{
use SoftDeletes;
protected $table = 'se_question_choices';
protected $fillable = [
'question_id',
'label',
'content',
'is_correct',
'media',
'media_object_id',
'position',
];
public function question()
{
return $this->belongsTo(Question::class, 'question_id');
}
}

@ -0,0 +1,33 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class QuestionGroup extends Model
{
use SoftDeletes;
protected $table = 'se_question_groups';
protected $fillable = [
'content',
'content_vi',
'exercise_id',
'is_question_order_fixed',
'is_option_order_fixed',
'position',
'paragraph',
'media_object_id',
];
public function exercise()
{
return $this->belongsTo(Exercise::class, 'exercise_id');
}
public function questions()
{
return $this->hasMany(Question::class, 'group_id');
}
}

@ -0,0 +1,24 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class QuestionType extends Model
{
use SoftDeletes;
protected $table = 'se_question_types';
protected $fillable = [
'name',
'code',
'description',
'status',
];
public function questions()
{
return $this->hasMany(Question::class, 'question_type_id');
}
}

@ -0,0 +1,23 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Skill extends Model
{
use SoftDeletes;
protected $table = 'se_skills';
protected $fillable = [
'name',
'code',
'description',
];
public function exercises()
{
return $this->hasMany(Exercise::class, 'skill_id');
}
}

@ -0,0 +1,10 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Subject extends Model
{
//
}

@ -0,0 +1,25 @@
<?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('se_subjects', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('code')->unique();
$table->text('description')->nullable();
$table->integer('status')->default(1); // true = active, false = inactive
$table->timestamps();
$table->softDeletes(); // deleted_at
});
}
public function down(): void
{
Schema::dropIfExists('se_subjects');
}
};

@ -0,0 +1,25 @@
<?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('se_categories', function (Blueprint $table) {
$table->id();
$table->string('content');
$table->string('content_vi')->nullable();
$table->text('description')->nullable();
$table->integer('status')->default(1);
$table->timestamps();
$table->softDeletes();
});
}
public function down(): void
{
Schema::dropIfExists('se_categories');
}
};

@ -0,0 +1,24 @@
<?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('se_skills', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('code')->unique();
$table->text('description')->nullable();
$table->timestamps();
$table->softDeletes();
});
}
public function down(): void
{
Schema::dropIfExists('se_skills');
}
};

@ -0,0 +1,25 @@
<?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('se_question_types', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->text('description')->nullable();
$table->string('code')->unique();
$table->integer('status')->default(1);
$table->timestamps();
$table->softDeletes();
});
}
public function down(): void
{
Schema::dropIfExists('se_question_types');
}
};

@ -0,0 +1,27 @@
<?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('se_media', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('object_id');
$table->string('file_name');
$table->string('file_url');
$table->string('mime_type');
$table->unsignedBigInteger('size_bytes');
$table->integer('position')->nullable();
$table->timestamps();
$table->softDeletes();
});
}
public function down(): void
{
Schema::dropIfExists('se_media');
}
};

@ -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 {
public function up(): void
{
Schema::create('se_exercises', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('subject_id');
$table->string('lesson_name');
$table->text('description')->nullable();
$table->integer('level')->default(0);
$table->string('avatar')->nullable();
$table->integer('status')->default(1); //
$table->unsignedBigInteger('category_id');
$table->unsignedBigInteger('skill_id');
$table->string('year')->nullable();
$table->unsignedBigInteger('media_object_id')->nullable();
$table->timestamps();
$table->softDeletes();
});
}
public function down(): void
{
Schema::dropIfExists('se_exercises');
}
};

@ -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('se_question_groups', function (Blueprint $table) {
$table->id();
$table->text('content');
$table->text('content_vi')->nullable();
$table->unsignedBigInteger('exercise_id');
$table->integer('is_question_order_fixed')->default(0);
$table->integer('is_option_order_fixed')->default(0);
$table->integer('position')->default(0);
$table->text('paragraph')->nullable();
$table->unsignedBigInteger('media_object_id')->nullable();
$table->timestamps();
$table->softDeletes();
});
}
public function down(): void
{
Schema::dropIfExists('se_question_groups');
}
};

@ -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 {
public function up(): void
{
Schema::create('se_questions', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('exercise_id');
$table->text('content');
$table->text('description')->nullable();
$table->unsignedBigInteger('group_id')->nullable();
$table->unsignedBigInteger('question_type_id');
$table->integer('level')->default(0);
$table->integer('score')->default(1);
$table->text('answer')->nullable();
$table->text('explanation')->nullable();
$table->text('hint')->nullable();
$table->unsignedBigInteger('media_object_id')->nullable();
$table->timestamps();
$table->softDeletes();
});
}
public function down(): void
{
Schema::dropIfExists('se_questions');
}
};

@ -0,0 +1,27 @@
<?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('se_exercise_questions', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('exercise_id');
$table->unsignedBigInteger('question_id');
$table->integer('position')->default(0);
$table->timestamps();
$table->softDeletes();
});
}
public function down(): void
{
Schema::dropIfExists('se_exercise_questions');
}
};

@ -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('se_question_choices', function (Blueprint $table) {
$table->id();
// Chỉ giữ cột, không còn ràng buộc FK
$table->unsignedBigInteger('question_id');
$table->string('label')->nullable();
$table->text('content')->nullable();
$table->integer('is_correct')->default(0); // 0 = false, 1 = true
// $table->json('media')->nullable();
$table->unsignedBigInteger('media_object_id')->nullable();
$table->integer('position')->default(0);
$table->timestamps();
$table->softDeletes();
});
}
public function down(): void
{
Schema::dropIfExists('se_question_choices');
}
};

@ -0,0 +1,25 @@
<?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('se_question_blanks', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('question_id');
$table->integer('position')->default(0);
$table->text('correct_answer');
$table->json('other_answers')->nullable();
$table->timestamps();
$table->softDeletes();
});
}
public function down(): void
{
Schema::dropIfExists('se_question_blanks');
}
};
Loading…
Cancel
Save