repository = $test; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Joolano\Joolano\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(\Joolano\Joolano\Repositories\Presenter\TestPresenter::class) ->$function(); } $tests = $this->repository->paginate(); return $this->response->title(trans('joolano::test.names')) ->view('joolano::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 = 'joolano::test.show'; } else { $view = 'joolano::test.new'; } return $this->response->title(trans('app.view') . ' ' . trans('joolano::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->title(trans('app.new') . ' ' . trans('joolano::test.name')) ->view('joolano::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('joolano::test.name')])) ->code(204) ->status('success') ->url(guard_url('joolano/test/' . $test->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/joolano/test')) ->redirect(); } } /** * Show test for editing. * * @param Request $request * @param Model $test * * @return Response */ public function edit(TestRequest $request, Test $test) { return $this->response->title(trans('app.edit') . ' ' . trans('joolano::test.name')) ->view('joolano::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('joolano::test.name')])) ->code(204) ->status('success') ->url(guard_url('joolano/test/' . $test->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('joolano/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('joolano::test.name')])) ->code(202) ->status('success') ->url(guard_url('joolano/test/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('joolano/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('joolano::test.name')])) ->status("success") ->code(202) ->url(guard_url('joolano/test')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/joolano/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('joolano::test.name')])) ->status("success") ->code(202) ->url(guard_url('/joolano/test')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/joolano/test/')) ->redirect(); } } }