repository = $slider; parent::__construct(); } /** * Display a list of slider. * * @return Response */ public function index(SliderAdminWebRequest $request) { if ($request->wantsJson()) { $sliders = $this->repository->setPresenter('\\Litecms\\Slider\\Repositories\\Presenter\\SliderListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->all(); return response()->json($sliders, 200); } $this ->theme->prependTitle(trans('slider::slider.names').' :: '); return $this->theme->of('slider::admin.slider.index')->render(); } /** * Display slider. * * @param Request $request * @param Model $slider * * @return Response */ public function show(SliderAdminWebRequest $request, Slider $slider) { if (!$slider->exists) { return response()->view('slider::admin.slider.new', compact('slider')); } Form::populate($slider); return response()->view('slider::admin.slider.show', compact('slider')); } /** * Show the form for creating a new slider. * * @param Request $request * * @return Response */ public function create(SliderAdminWebRequest $request) { $slider = $this->repository->newInstance([]); Form::populate($slider); return response()->view('slider::admin.slider.create', compact('slider')); } /** * Create new slider. * * @param Request $request * * @return Response */ public function store(SliderAdminWebRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id('admin.web'); $slider = $this->repository->create($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('slider::slider.name')]), 'code' => 204, 'redirect' => trans_url('/admin/slider/slider/'.$slider->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, ], 400); } } /** * Show slider for editing. * * @param Request $request * @param Model $slider * * @return Response */ public function edit(SliderAdminWebRequest $request, Slider $slider) { Form::populate($slider); return response()->view('slider::admin.slider.edit', compact('slider')); } /** * Update the slider. * * @param Request $request * @param Model $slider * * @return Response */ public function update(SliderAdminWebRequest $request, Slider $slider) { try { $attributes = $request->all(); $slider->update($attributes); return response()->json([ 'message' => trans('messages.success.updated', ['Module' => trans('slider::slider.name')]), 'code' => 204, 'redirect' => trans_url('/admin/slider/slider/'.$slider->getRouteKey()) ], 201); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/slider/slider/'.$slider->getRouteKey()), ], 400); } } /** * Remove the slider. * * @param Model $slider * * @return Response */ public function destroy(SliderAdminWebRequest $request, Slider $slider) { try { $t = $slider->delete(); return response()->json([ 'message' => trans('messages.success.deleted', ['Module' => trans('slider::slider.name')]), 'code' => 202, 'redirect' => trans_url('/admin/slider/slider/0'), ], 202); } catch (Exception $e) { return response()->json([ 'message' => $e->getMessage(), 'code' => 400, 'redirect' => trans_url('/admin/slider/slider/'.$slider->getRouteKey()), ], 400); } } }