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