1
0
mirror of https://github.com/robonen/education-project.git synced 2026-03-20 02:44:31 +00:00
Files
education-project/app/Http/Controllers/AnswerToTaskController.php
2020-12-09 19:02:38 +07:00

56 lines
1.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Http\Controllers;
use App\Models\AnswerToTask;
use Illuminate\Http\Request;
use App\Models\Task;
use Illuminate\Support\Facades\Auth;
use App\Models\Student;
use App\Models\TaskFile;
class AnswerToTaskController extends Controller
{
public function store(Task $task, Request $request) {
$input = $request->all();
$input->class_id = $task->class_id; // Не работает
$input->student_id = Student::where('user_id', '=', Auth::id())->get(['id']); // Не работает
$answer = AnswerToTask::create($input);
return response()->json($answer, 201);
}
public function show(Task $task, Student $student) {
$answer = AnswerToTask::where([
['student_id', '=', $student->id],
['task_id', '=', $task->id]
])->get();
$file = TaskFile::where([
['student_id', '=', $student->id],
['task_id', '=', $task->id]
])
->get(['id','name', 'type', 'url']);
return response()->json([
'answer' => $answer,
'files' => $file
],200);
}
public function delete(AnswerToTask $answer){
$answer->delete();
return response()->json(true, 204);
}
public function update(AnswerToTask $answer, Request $request) {
$answer->description = $request->input('description');
$answer->save();
return $answer;
}
}