public function material_popup($id) { $test = Test::with('page')->has('page')->find($id); if ($test && !$test->page->hidden) { return view('test.material-popup')->with(['test' => $test]); } else { return redirect('/test/' . $id); } }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $test = Test::with('questions', 'questions.answers')->findOrFail($id); foreach ($test->questions as $question) { foreach ($question->answers as $answer) { $answer->delete(); } $question->delete(); } $test->delete(); }