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