repository = $test; parent::__construct(); } /** * Display a listing of the resource. * * @return Response */ public function index(TestUserRequest $request) { $this->repository->pushCriteria(new \Lavalite\Tewst\Repositories\Criteria\TestUserCriteria()); $tests = $this->repository->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate(); $this->theme->prependTitle(trans('tewst::test.names').' :: '); return $this->theme->of('tewst::user.test.index', compact('tests'))->render(); } /** * Display the specified resource. * * @param Request $request * @param Test $test * * @return Response */ public function show(TestUserRequest $request, Test $test) { Form::populate($test); return $this->theme->of('tewst::user.test.show', compact('test'))->render(); } /** * Show the form for creating a new resource. * * @param Request $request * * @return Response */ public function create(TestUserRequest $request) { $test = $this->repository->newInstance([]); Form::populate($test); return $this->theme->of('tewst::user.test.create', compact('test'))->render(); } /** * Display the specified resource. * * @param Request $request * * @return Response */ public function store(TestUserRequest $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->responseRedirect = trans_url('/user/tewst/test'); return $this -> respond($request); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Show the form for editing the specified resource. * * @param Request $request * @param Test $test * * @return Response */ public function edit(TestUserRequest $request, Test $test) { Form::populate($test); return $this->theme->of('tewst::user.test.edit', compact('test'))->render(); } /** * Update the specified resource. * * @param Request $request * @param Test $test * * @return Response */ public function update(TestUserRequest $request, Test $test) { try { $this->repository->update($request->all(), $test->getRouteKey()); $this->responseCode = 204; $this->responseMessage = trans('messages.success.updated', ['Module' => trans('tewst::test.name')]); $this->responseRedirect = trans_url('/user/tewst/test'); return $this -> respond($request); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } /** * Remove the specified resource. * * @param int $id * * @return Response */ public function destroy(TestUserRequest $request, Test $test) { try { $this->repository->delete($test->getRouteKey()); $this->responseCode = 204; $this->responseMessage = trans('messages.success.deleted', ['Module' => trans('tewst::test.name')]); $this->responseRedirect = trans_url('/user/tewst/test'); return $this -> respond($request); } catch (Exception $e) { redirect()->back()->withInput()->with('message', $e->getMessage())->with('code', 400); } } }