repository = $test; } /** * Display a list of test. * * @return Response */ public function index(TestAdminRequest $request) { $tests = $this->repository->setPresenter('\\Tewst\\Tewst\\Repositories\\Presenter\\TestListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this ->theme->prependTitle(trans('tewst::test.names').' :: '); $view = $this->theme->of('tewst::admin.test.index')->render(); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('tewst::test.name')]); $this->responseData = $tests['data']; $this->responseMeta = $tests['meta']; $this->responseView = $view; $this->responseRedirect = ''; return $this->respond($request); } /** * Display test. * * @param Request $request * @param int $id * * @return Response */ public function show(TestAdminRequest $request, Test $test) { if (!$test->exists) { $this->responseCode = 404; $this->responseMessage = trans('messages.success.notfound', ['Module' => trans('tewst::test.name')]); $this->responseView = view('tewst::admin.test.new'); return $this -> respond($request); } Form::populate($test); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('tewst::test.name')]); $this->responseData = $test; $this->responseView = view('tewst::admin.test.show', compact('test')); return $this -> respond($request); } /** * Show the form for creating a new test. * * @param Request $request * * @return Response */ public function create(TestAdminRequest $request) { $test = $this->repository->newInstance([]); Form::populate($test); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('tewst::test.name')]); $this->responseData = $test; $this->responseView = view('tewst::admin.test.create', compact('test')); return $this -> respond($request); } /** * Create new test. * * @param Request $request * * @return Response */ public function store(TestAdminRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $test = $this->repository->create($attributes); $this->responseCode = 201; $this->responseMessage = trans('messages.success.created', ['Module' => trans('tewst::test.name')]); $this->responseData = $test; $this->responseMeta = ''; $this->responseRedirect = trans_url('/admin/tewst/test/'.$test->getRouteKey()); $this->responseView = view('tewst::admin.test.create', compact('test')); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); return $this -> respond($request); } } /** * Show test for editing. * * @param Request $request * @param int $id * * @return Response */ public function edit(TestAdminRequest $request, Test $test) { Form::populate($test); $this->responseCode = 200; $this->responseMessage = trans('messages.success.loaded', ['Module' => trans('tewst::test.name')]); $this->responseData = $test; $this->responseView = view('tewst::admin.test.edit', compact('test')); return $this -> respond($request); } /** * Update the test. * * @param Request $request * @param int $id * * @return Response */ public function update(TestAdminRequest $request, Test $test) { try { $attributes = $request->all(); $test->update($attributes); $this->responseCode = 204; $this->responseMessage = trans('messages.success.updated', ['Module' => trans('tewst::test.name')]); $this->responseData = $test; $this->responseRedirect = trans_url('/admin/tewst/test/'.$test->getRouteKey()); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); $this->responseRedirect = trans_url('/admin/tewst/test/'.$test->getRouteKey()); return $this -> respond($request); } } /** * Remove the test. * * @param int $id * * @return Response */ public function destroy(TestAdminRequest $request, Test $test) { try { $t = $test->delete(); $this->responseCode = 202; $this->responseMessage = trans('messages.success.deleted', ['Module' => trans('tewst::test.name')]); $this->responseRedirect = trans_url('/admin/tewst/test/0'); return $this -> respond($request); } catch (Exception $e) { $this->responseCode = 400; $this->responseMessage = $e->getMessage(); $this->responseRedirect = trans_url('/admin/tewst/test/'.$test->getRouteKey()); return $this -> respond($request); } } }