repository = $test; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litecms\Testpackage\Repositories\Criteria\TestResourceCriteria::class); } /** * Display a list of test. * * @return Response */ public function index(TestRequest $request) { return $this->repository ->setPresenter(\Litecms\Testpackage\Repositories\Presenter\TestPresenter::class) ->paginate(); } /** * Display test. * * @param Request $request * @param Model $test * * @return Response */ public function show(TestRequest $request, Test $test) { return $test->setPresenter(\Litecms\Testpackage\Repositories\Presenter\TestListPresenter::class); ; } /** * Create new test. * * @param Request $request * * @return Response */ public function store(TestRequest $request) { try { $data = $request->all(); $data['user_id'] = user_id(); $data['user_type'] = user_type(); $data = $this->repository->create($data); $message = trans('messages.success.created', ['Module' => trans('testpackage::test.name')]); $code = 204; $status = 'success'; $url = guard_url('testpackage/test/' . $test->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('testpackage/test'); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Update the test. * * @param Request $request * @param Model $test * * @return Response */ public function update(TestRequest $request, Test $test) { try { $data = $request->all(); $test->update($data); $message = trans('messages.success.updated', ['Module' => trans('testpackage::test.name')]); $code = 204; $status = 'success'; $url = guard_url('testpackage/test/' . $test->getRouteKey()); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('testpackage/test/' . $test->getRouteKey()); } return compact('data', 'message', 'code', 'status', 'url'); } /** * Remove the test. * * @param Model $test * * @return Response */ public function destroy(TestRequest $request, Test $test) { try { $test->delete(); $message = trans('messages.success.deleted', ['Module' => trans('testpackage::test.name')]); $code = 202; $status = 'success'; $url = guard_url('testpackage/test/0'); } catch (Exception $e) { $message = $e->getMessage(); $code = 400; $status = 'error'; $url = guard_url('testpackage/test/' . $test->getRouteKey()); } return compact('message', 'code', 'status', 'url'); } /** * Return the form elements as json. * * @param String $element * * @return json */ public function form($element = 'fields') { $form = new Form(); return $form->form($element, true); } }