form = StudyForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('beo.case_study.modules'), 'case_study', guard_url('case_study')); } /** * Display a list of study. * * @return Response */ public function index(StudyRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $page = Study::pushScope(new RequestScope()) ->pushScope(new StudyResourceScope()) ->simplePaginate($pageLimit); $data = new StudiesCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('case_study::study.names')) ->view('case_study::study.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display study. * * @param Request $request * @param Model $study * * @return Response */ public function show(StudyRequest $request, Study $model) { $form = $this->form; $modules = $this->modules; $data = new StudyResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('case_study::study.name')) ->data(compact('data', 'form', 'modules')) ->view('case_study::study.show') ->output(); } /** * Show the form for creating a new study. * * @param Request $request * * @return Response */ public function create(StudyRequest $request, Study $model) { $form = $this->form; $modules = $this->modules; $data = new StudyResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('case_study::study.name')) ->view('case_study::study.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new study. * * @param Request $request * * @return Response */ public function store(StudyRequest $request, Study $model) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $model = $model->create($attributes); $data = new StudyResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('case_study::study.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('case_study/study/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/case_study/study')) ->redirect(); } } /** * Show study for editing. * * @param Request $request * @param Model $study * * @return Response */ public function edit(StudyRequest $request, Study $model) { $form = $this->form; $modules = $this->modules; $data = new StudyResource($model); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('case_study::study.name')) ->view('case_study::study.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the study. * * @param Request $request * @param Model $study * * @return Response */ public function update(StudyRequest $request, Study $model) { try { $attributes = $request->all(); $model = $model->update($attributes); $data = new StudyResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('case_study::study.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('case_study/study/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('case_study/study/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the study. * * @param Model $study * * @return Response */ public function destroy(StudyRequest $request, Study $model) { try { $model->delete(); $data = new StudyResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('case_study::study.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('case_study/study/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('case_study/study/' . $model->getRouteKey())) ->redirect(); } } }