repository = $sampleset; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litepci\Sampleset\Repositories\Criteria\SamplesetResourceCriteria::class); } /** * Display a list of sampleset. * * @return Response */ public function index(SamplesetRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Litepci\Sampleset\Repositories\Presenter\SamplesetPresenter::class) ->$function(); } $samplesets = $this->repository->paginate(); return $this->response->title(trans('sampleset::sampleset.names')) ->view('sampleset::sampleset.index', true) ->data(compact('samplesets')) ->output(); } /** * Display sampleset. * * @param Request $request * @param Model $sampleset * * @return Response */ public function show(SamplesetRequest $request, Sampleset $sampleset) { if ($sampleset->exists) { $view = 'sampleset::sampleset.show'; } else { $view = 'sampleset::sampleset.new'; } return $this->response->title(trans('app.view') . ' ' . trans('sampleset::sampleset.name')) ->data(compact('sampleset')) ->view($view, true) ->output(); } /** * Show the form for creating a new sampleset. * * @param Request $request * * @return Response */ public function create(SamplesetRequest $request) { $sampleset = $this->repository->newInstance([]); return $this->response->title(trans('app.new') . ' ' . trans('sampleset::sampleset.name')) ->view('sampleset::sampleset.create', true) ->data(compact('sampleset')) ->output(); } /** * Create new sampleset. * * @param Request $request * * @return Response */ public function store(SamplesetRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $sampleset = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('sampleset::sampleset.name')])) ->code(204) ->status('success') ->url(guard_url('sampleset/sampleset/' . $sampleset->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/sampleset/sampleset')) ->redirect(); } } /** * Show sampleset for editing. * * @param Request $request * @param Model $sampleset * * @return Response */ public function edit(SamplesetRequest $request, Sampleset $sampleset) { return $this->response->title(trans('app.edit') . ' ' . trans('sampleset::sampleset.name')) ->view('sampleset::sampleset.edit', true) ->data(compact('sampleset')) ->output(); } /** * Update the sampleset. * * @param Request $request * @param Model $sampleset * * @return Response */ public function update(SamplesetRequest $request, Sampleset $sampleset) { try { $attributes = $request->all(); $sampleset->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('sampleset::sampleset.name')])) ->code(204) ->status('success') ->url(guard_url('sampleset/sampleset/' . $sampleset->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('sampleset/sampleset/' . $sampleset->getRouteKey())) ->redirect(); } } /** * Remove the sampleset. * * @param Model $sampleset * * @return Response */ public function destroy(SamplesetRequest $request, Sampleset $sampleset) { try { $sampleset->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('sampleset::sampleset.name')])) ->code(202) ->status('success') ->url(guard_url('sampleset/sampleset/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('sampleset/sampleset/' . $sampleset->getRouteKey())) ->redirect(); } } /** * Remove multiple sampleset. * * @param Model $sampleset * * @return Response */ public function delete(SamplesetRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('sampleset::sampleset.name')])) ->status("success") ->code(202) ->url(guard_url('sampleset/sampleset')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/sampleset/sampleset')) ->redirect(); } } /** * Restore deleted samplesets. * * @param Model $sampleset * * @return Response */ public function restore(SamplesetRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('sampleset::sampleset.name')])) ->status("success") ->code(202) ->url(guard_url('/sampleset/sampleset')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/sampleset/sampleset/')) ->redirect(); } } }