1
0
tinklu-it-projektas/database/seeders/DatabaseSeeder.php

89 lines
2.5 KiB
PHP

<?php
namespace Database\Seeders;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use App\Models\MultipleChoiceAnswers;
use App\Models\Question;
use App\Models\SingleChoiceAnswer;
use App\Models\SingleQuestionAnswers;
use App\Models\Test;
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"
]);
User::create([
'name' => "Alice student",
'email' => "alice@student",
'password' => Hash::make("alice"),
'role' => "student"
]);
$test = Test::create([
"name" => "Matematika",
"user_id" => $teacher->id
]);
{
$question = Question::create([
"test_id" => $test->id,
"question" => "1+1=?",
"answer_type" => "single_answer",
]);
SingleQuestionAnswers::create([
"question_id" => $question->id,
"answer" => "2"
]);
}
{
$question = Question::create([
"test_id" => $test->id,
"question" => "Gyvenimo prasme",
"answer_type" => "single_choice",
]);
SingleChoiceAnswer::create([
"question_id" => $question->id,
"correct_answer" => "42",
"incorrect_answer1" => "Kates",
"incorrect_answer3" => "Sunys",
]);
}
{
$question = Question::create([
"test_id" => $test->id,
"question" => "Siandienos orai",
"answer_type" => "multiple_choice",
]);
MultipleChoiceAnswers::create([
"question_id" => $question->id,
"answer1" => "Sninga", "is_answer1_correct" => true,
"answer2" => "Lija", "is_answer2_correct" => true,
"answer4" => "Idk, paziurek per langa", "is_answer4_correct" => false,
]);
}
}
}