public function sortQuestions($project, Request $request) { if ($request->has('listid')) { $i = 1; foreach ($request->get('listid') as $qid) { $search['id'] = $qid; $data['sort'] = $i; $question = Question::updateOrCreate($search, $data); $i++; } return response()->json(array('success' => $question)); } else { return response()->json(array('success' => false)); } }