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