Skip to content

Commit

Permalink
implement store questions on inputtask
Browse files Browse the repository at this point in the history
  • Loading branch information
danivideda committed Dec 3, 2020
1 parent c984061 commit 1b94ddf
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions app/Http/Controllers/AssignmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use App\Models\Classroom;
use Illuminate\Http\Request;

use function PHPUnit\Framework\isEmpty;
use function PHPUnit\Framework\isNull;

class AssignmentController extends Controller
{
public function index(Classroom $classroom) {
Expand Down Expand Up @@ -61,16 +64,28 @@ public function input(Classroom $classroom, Assignment $assignment) {
]);
}

public function storeInput(Request $request) {
public function storeInput(Request $request, $classroom, $assignment) {
$this->validate($request, [
'question' => 'required'
]);

Assignment::create([
$assignment = Assignment::where('id', $assignment)->first();

if (!$assignment->questions) {
$questions = [];
} else {
$questions = $assignment->questions;
}

$questions[] = [
'type' => 'essay',
'question' => $request->question
]);
];

$assignment->questions = $questions;
$assignment->save();

return redirect()->route('assignment');
return redirect()->route('assignment', [$classroom]);
}

public function show(Classroom $classroom) {
Expand Down

0 comments on commit 1b94ddf

Please sign in to comment.