public static function destroy($SpaceID) { if (!AuthController::checkPermission()) { return redirect('/'); } $space = Spaces::find($SpaceID); $answers = Answers::where('SpaceID', '=', $SpaceID)->get()->toArray(); foreach ($answers as $answer) { Answers::destroy($answer['id']); } $space->delete(); return; }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public static function destroy($id) { if (!AuthController::checkPermission()) { return redirect('/'); } $question = Questions::find($id); @unlink(public_path('images/imageQuestion/' . $question['Photo'])); $postid = $question['PostID']; $format = Posts::find($postid)['FormatID']; if ($format == 1) { $answers = Answers::where('QuestionID', '=', $id)->get()->toArray(); foreach ($answers as $answer) { Answers::destroy($answer['id']); } } else { if ($format == 2) { $spaces = Spaces::where('QuestionID', '=', $id)->get()->toArray(); foreach ($spaces as $value) { SpacesController::destroy($value['id']); } } } $question->delete(); return redirect(route('user.viewpost', $postid)); }
public static function destroy($id) { if (!AuthController::checkPermission()) { return redirect('/'); } $question = Questions::find($id); @unlink(public_path('images/imageQuestion/' . $question['Photo'])); $postid = $question['PostID']; $format = $question['FormatID']; switch ($format) { case 1: $answers = Answers::where('QuestionID', '=', $id)->get()->toArray(); foreach ($answers as $answer) { Answers::destroy($answer['id']); } break; case 2: $spaces = Spaces::where('QuestionID', '=', $id)->get()->toArray(); foreach ($spaces as $value) { SpacesController::destroy($value['id']); } break; case 3: $answers = Answers::where('QuestionID', '=', $id)->get()->toArray(); foreach ($answers as $answer) { Answers::destroy($answer['id']); } break; case 4: $answers = Answers::where('QuestionID', '=', $id)->get()->toArray(); foreach ($answers as $answer) { Answers::destroy($answer['id']); } break; case 5: $subq = Subquestions::where('QuestionID', '=', $id)->get()->toArray(); foreach ($subq as $s) { SubquestionsController::destroy($s['id']); } } $question->delete(); return redirect(route('user.viewpost', $postid)); }