92 lines
1.9 KiB
PHP
92 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Question;
|
|
use App\Models\Test;
|
|
use Illuminate\Http\Request;
|
|
|
|
class QuestionController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$validated = $request->validate([
|
|
"question" => "required|string",
|
|
"answer" => "required|string",
|
|
"points" => "required|integer|min:1",
|
|
"test_id" => "required|integer",
|
|
]);
|
|
|
|
Question::create($validated);
|
|
|
|
return redirect(route("tests.edit", [
|
|
"test" => Test::where("id", $validated["test_id"])->first()
|
|
]));
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(Question $question)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(Question $question)
|
|
{
|
|
return view("questions.edit", [
|
|
"question" => $question,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, Question $question)
|
|
{
|
|
$validated = $request->validate([
|
|
"question" => "required|string",
|
|
"answer" => "required|string",
|
|
"points" => "required|integer|min:1"
|
|
]);
|
|
|
|
$question->update($validated);
|
|
|
|
return view("tests.edit", [
|
|
"test" => $validated["test_id"]
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(Question $question)
|
|
{
|
|
$question->delete();
|
|
|
|
return redirect(route("tests.edit", $question->test_id));
|
|
}
|
|
}
|