repository = $question; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Ebuy\Question\Repositories\Criteria\QuestionResourceCriteria::class); } /** * Display a list of question. * * @return Response */ public function index(QuestionRequest $request) { return $this->repository ->setPresenter(\Ebuy\Question\Repositories\Presenter\QuestionPresenter::class) ->paginate(); } /** * Display question. * * @param Request $request * @param Model $question * * @return Response */ public function show(QuestionRequest $request, Question $question) { return $question->setPresenter(\Ebuy\Question\Repositories\Presenter\QuestionListPresenter::class); ; } /** * Create new question. * * @param Request $request * * @return Response */ public function store(QuestionRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('question::question.name')]); $code = 204; $status = 'success'; $url = guard_url('question/question/' . $question->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('question/question'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the question. * * @param Request $request * @param Model $question * * @return Response */ public function update(QuestionRequest $request, Question $question) { try { $data = $request->all(); $question->update($data); $message = trans('messages.success.updated', ['Module' => trans('question::question.name')]); $code = 204; $status = 'success'; $url = guard_url('question/question/' . $question->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('question/question/' . $question->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the question. * * @param Model $question * * @return Response */ public function destroy(QuestionRequest $request, Question $question) { try { $question->delete(); $message = trans('messages.success.deleted', ['Module' => trans('question::question.name')]); $code = 202; $status = 'success'; $url = guard_url('question/question/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('question/question/' . $question->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }