form = TestimonialForm::setAttributes()->toArray(); $this->modules = $this->modules(config('litecms.testimonial.modules'), 'testimonial', guard_url('testimonial')); $this->repository = $testimonial; } /** * Display a list of testimonial. * * @return Response */ public function index(TestimonialRequest $request) { $pageLimit = $request->input('pageLimit', config('database.pagination.limit')); $data = $this->repository ->pushFilter(RequestFilter::class) ->pushFilter(TestimonialResourceFilter::class) ->setPresenter(TestimonialListPresenter::class) ->simplePaginate($pageLimit) // ->withQueryString() ->toArray(); extract($data); $form = $this->form; $modules = $this->modules; return $this->response->setMetaTitle(trans('testimonial::testimonial.names')) ->view('testimonial::testimonial.index') ->data(compact('data', 'meta', 'links', 'modules', 'form')) ->output(); } /** * Display testimonial. * * @param Request $request * @param Model $testimonial * * @return Response */ public function show(TestimonialRequest $request, TestimonialRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response ->setMetaTitle(trans('app.view') . ' ' . trans('testimonial::testimonial.name')) ->data(compact('data', 'form', 'modules', 'form')) ->view('testimonial::testimonial.show') ->output(); } /** * Show the form for creating a new testimonial. * * @param Request $request *x * @return Response */ public function create(TestimonialRequest $request, TestimonialRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('testimonial::testimonial.name')) ->view('testimonial::testimonial.create') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Create new testimonial. * * @param Request $request * * @return Response */ public function store(TestimonialRequest $request, TestimonialRepositoryInterface $repository) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $repository->create($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.created', ['Module' => trans('testimonial::testimonial.name')])) ->code(204) ->data(compact('data')) ->status('success') ->url(guard_url('testimonial/testimonial/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/testimonial/testimonial')) ->redirect(); } } /** * Show testimonial for editing. * * @param Request $request * @param Model $testimonial * * @return Response */ public function edit(TestimonialRequest $request, TestimonialRepositoryInterface $repository) { $form = $this->form; $modules = $this->modules; $data = $repository->toArray(); return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('testimonial::testimonial.name')) ->view('testimonial::testimonial.edit') ->data(compact('data', 'form', 'modules')) ->output(); } /** * Update the testimonial. * * @param Request $request * @param Model $testimonial * * @return Response */ public function update(TestimonialRequest $request, TestimonialRepositoryInterface $repository) { try { $attributes = $request->all(); $repository->update($attributes); $data = $repository->toArray(); return $this->response->message(trans('messages.success.updated', ['Module' => trans('testimonial::testimonial.name')])) ->code(204) ->status('success') ->data(compact('data')) ->url(guard_url('testimonial/testimonial/' . $data['id'])) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('testimonial/testimonial/' . $repository->getRouteKey())) ->redirect(); } } /** * Remove the testimonial. * * @param Model $testimonial * * @return Response */ public function destroy(TestimonialRequest $request, TestimonialRepositoryInterface $repository) { try { $repository->delete(); $data = $repository->toArray(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('testimonial::testimonial.name')])) ->code(202) ->status('success') ->data(compact('data')) ->url(guard_url('testimonial/testimonial/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('testimonial/testimonial/' . $repository->getRouteKey())) ->redirect(); } } }