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