repository = $slider; parent::__construct(); } /** * Display a list of slider. * * @return Response */ public function index(SliderRequest $request) { if ($request->wantsJson()) { return $this->getJson($request); } $this ->theme->prependTitle(trans('slider::slider.names').' :: '); return $this->theme->of('slider::admin.slider.index')->render(); } /** * Display a list of slider. * * @return Response */ public function getJson(SliderRequest $request) { $pageLimit = $request->input('pageLimit'); $sliders = $this->repository ->pushCriteria(app('Litepie\Repository\Criteria\RequestCriteria')) ->setPresenter('\\Mbc\\Slider\\Repositories\\Presenter\\SliderListPresenter') ->scopeQuery(function($query){ return $query->orderBy('id','DESC'); })->paginate($pageLimit); $sliders['recordsTotal'] = $sliders['meta']['pagination']['total']; $sliders['recordsFiltered'] = $sliders['meta']['pagination']['total']; $sliders['request'] = $request->all(); return response()->json($sliders, 200); } /** * Display slider. * * @param Request $request * @param Model $slider * * @return Response */ public function show(SliderRequest $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(SliderRequest $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(SliderRequest $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(SliderRequest $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(SliderRequest $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(SliderRequest $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); } } }