form = SliderForm::grouped(false) ->setAttributes() ->toArray(); $this->modules = $this->modules(config('litecms.slider.modules'), 'slider', guard_url('slider')); } /** * Display a list of slider. * * @return Response */ public function index(SliderRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $page = Slider::pushScope(new RequestScope()) ->pushScope(new SliderResourceScope()) ->simplePaginate($pageLimit); $data = new SlidersCollection($page); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('slider::slider.names')) ->view('slider::slider.index') ->data(compact('data', 'modules', 'form')) ->output(); } /** * Display slider. * * @param Request $request * @param Model $slider * * @return Response */ public function show(SliderRequest $request, Slider $model) { $form = $this->form; $modules = $this->modules; $data = new SliderResource($model); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('slider::slider.name')) ->data(compact('data', 'form', 'modules')) ->view('slider::slider.show') ->output(); } /** * Show the form for creating a new slider. * * @param Request $request * * @return Response */ public function create(SliderRequest $request, Slider $model) { $form = $this->form; $modules = $this->modules; $data = new SliderResource($model); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('slider::slider.name')) ->view('slider::slider.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new slider. * * @param Request $request * * @return Response */ public function store(SliderRequest $request, Slider $model) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $model = $model->create($attributes); $data = new SliderResource($model); return $this->response->message(trans('messages.success.created', ['Module' => trans('slider::slider.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('slider/slider/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/slider/slider')) ->redirect(); } } /** * Show slider for editing. * * @param Request $request * @param Model $slider * * @return Response */ public function edit(SliderRequest $request, Slider $model) { $form = $this->form; $modules = $this->modules; $data = new SliderResource($model); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('slider::slider.name')) ->view('slider::slider.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the slider. * * @param Request $request * @param Model $slider * * @return Response */ public function update(SliderRequest $request, Slider $model) { try { $attributes = $request->all(); $model = $model->update($attributes); $data = new SliderResource($model); return $this->response->message(trans('messages.success.updated', ['Module' => trans('slider::slider.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('slider/slider/' . $model->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('slider/slider/' . $model->getRouteKey())) ->redirect(); } } /** * Remove the slider. * * @param Model $slider * * @return Response */ public function destroy(SliderRequest $request, Slider $model) { try { $model->delete(); $data = new SliderResource($model); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('slider::slider.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('slider/slider/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('slider/slider/' . $model->getRouteKey())) ->redirect(); } } }