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