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