1
0
tinklu-it-projektas/app/Http/Controllers/AssignedTestsController.php

94 lines
2.1 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\AssignedTests;
use App\Models\MultipleChoiceAnswers;
use App\Models\SingleChoiceAnswer;
use App\Models\SingleQuestionAnswers;
use App\Models\Test;
use App\Models\User;
use Illuminate\Http\Request;
class AssignedTestsController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(Request $request)
{
//
}
/**
* 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([
"test_id" => "required|integer",
"student_id" => "required|integer"
]);
AssignedTests::create($validated);
return redirect(route("tests.edit", [
"test" => Test::where("id", $validated["test_id"])->first()
]));
}
/**
* Display the specified resource.
*/
public function show($assigned_student)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit($assigned_student)
{
$obj = AssignedTests::where("id", $assigned_student);
$obj->update([
"allowed" => "1"
]);
$test_id = $obj->first()->test_id;
return redirect(route("tests.edit", [
"test" => Test::where("id", $test_id)->first()
]));
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, AssignedTests $assigned_student)
{
// $test->update($validated);
}
/**
* Remove the specified resource from storage.
*/
public function destroy($assigned_student)
{
$obj = AssignedTests::where("id", $assigned_student);
$test_id = $obj->first()->test_id;
$obj->delete();
return redirect(route("tests.edit", [
"test" => Test::where("id", $test_id)->first()
]));
}
}