120 lines
3.5 KiB
PHP
120 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
|
|
|
use App\Models\AssignedTests;
|
|
use App\Models\MultipleChoiceAnswers;
|
|
use App\Models\Question;
|
|
use App\Models\SingleChoiceAnswer;
|
|
use App\Models\SingleQuestionAnswers;
|
|
use App\Models\Test;
|
|
use App\Models\TestQuestionResult;
|
|
use App\Models\TestResult;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
class DatabaseSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Seed the application's database.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
User::create([
|
|
'name' => "admin",
|
|
'email' => "admin@admin",
|
|
'password' => Hash::make("admin"),
|
|
'role' => "admin"
|
|
]);
|
|
$teacher = User::create([
|
|
'name' => "Bob teacher",
|
|
'email' => "bob@teacher",
|
|
'password' => Hash::make("bob"),
|
|
'role' => "teacher"
|
|
]);
|
|
$alice = User::create([
|
|
'name' => "Alice student",
|
|
'email' => "alice@student",
|
|
'password' => Hash::make("alice"),
|
|
'role' => "student"
|
|
]);
|
|
|
|
$test = Test::create([
|
|
"name" => "Matematika",
|
|
"user_id" => $teacher->id
|
|
]);
|
|
|
|
$question_1 = Question::create([
|
|
"test_id" => $test->id,
|
|
"question" => "1+1=?",
|
|
"answer_type" => "single_answer",
|
|
]);
|
|
SingleQuestionAnswers::create([
|
|
"question_id" => $question_1->id,
|
|
"answer" => "2"
|
|
]);
|
|
|
|
$question_2 = Question::create([
|
|
"test_id" => $test->id,
|
|
"question" => "Gyvenimo prasme",
|
|
"answer_type" => "single_choice",
|
|
]);
|
|
SingleChoiceAnswer::create([
|
|
"question_id" => $question_2->id,
|
|
"correct_answer" => "42",
|
|
"incorrect_answer1" => "Kates",
|
|
"incorrect_answer3" => "Sunys",
|
|
]);
|
|
|
|
$question_3 = Question::create([
|
|
"test_id" => $test->id,
|
|
"question" => "Siandienos orai",
|
|
"answer_type" => "multiple_choice",
|
|
]);
|
|
MultipleChoiceAnswers::create([
|
|
"question_id" => $question_3->id,
|
|
"answer1" => "Sninga", "is_answer1_correct" => true,
|
|
"answer2" => "Lija", "is_answer2_correct" => true,
|
|
"answer4" => "Idk, paziurek per langa", "is_answer4_correct" => false,
|
|
]);
|
|
|
|
{
|
|
AssignedTests::create([
|
|
"student_id" => $alice->id,
|
|
"test_id" => $test->id,
|
|
"allowed" => false
|
|
]);
|
|
|
|
$test_result = TestResult::create([
|
|
"student_id" => $alice->id,
|
|
"test_id" => $test->id,
|
|
"points" => 2.5,
|
|
"max_points" => 3
|
|
]);
|
|
|
|
TestQuestionResult::create([
|
|
"test_results_id" => $test_result->id,
|
|
"question_id" => $question_1->id,
|
|
"points" => 1,
|
|
"answer" => "2"
|
|
]);
|
|
TestQuestionResult::create([
|
|
"test_results_id" => $test_result->id,
|
|
"question_id" => $question_2->id,
|
|
"points" => 1,
|
|
"answer" => "42"
|
|
]);
|
|
TestQuestionResult::create([
|
|
"test_results_id" => $test_result->id,
|
|
"question_id" => $question_3->id,
|
|
"points" => 0.5,
|
|
"answer" => "Lija"
|
|
]);
|
|
}
|
|
|
|
}
|
|
}
|