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