repository = $feedback; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Feedback\Feedback\Repositories\Criteria\FeedbackResourceCriteria::class); } /** * Display a list of feedback. * * @return Response */ public function index(FeedbackRequest $request) { $view = $this->response->theme->listView(); if ($this->response->typeIs('json')) { $function = camel_case('get-' . $view); return $this->repository ->setPresenter(\Feedback\Feedback\Repositories\Presenter\FeedbackPresenter::class) ->$function(); } $feedback = $this->repository->paginate(); return $this->response->setMetaTitle(trans('feedback::feedback.names')) ->view('feedback::feedback.index', true) ->data(compact('feedback', 'view')) ->output(); } /** * Display feedback. * * @param Request $request * @param Model $feedback * * @return Response */ public function show(FeedbackRequest $request, Feedback $feedback) { if ($feedback->exists) { $view = 'feedback::feedback.show'; } else { $view = 'feedback::feedback.new'; } return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('feedback::feedback.name')) ->data(compact('feedback')) ->view($view, true) ->output(); } /** * Show the form for creating a new feedback. * * @param Request $request * * @return Response */ public function create(FeedbackRequest $request) { $feedback = $this->repository->newInstance([]); return $this->response->setMetaTitle(trans('app.new') . ' ' . trans('feedback::feedback.name')) ->view('feedback::feedback.create', true) ->data(compact('feedback')) ->output(); } /** * Create new feedback. * * @param Request $request * * @return Response */ public function store(FeedbackRequest $request) { try { $attributes = $request->all(); $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $feedback = $this->repository->create($attributes); return $this->response->message(trans('messages.success.created', ['Module' => trans('feedback::feedback.name')])) ->code(204) ->status('success') ->url(guard_url('feedback/feedback/' . $feedback->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/feedback/feedback')) ->redirect(); } } /** * Show feedback for editing. * * @param Request $request * @param Model $feedback * * @return Response */ public function edit(FeedbackRequest $request, Feedback $feedback) { return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('feedback::feedback.name')) ->view('feedback::feedback.edit', true) ->data(compact('feedback')) ->output(); } /** * Update the feedback. * * @param Request $request * @param Model $feedback * * @return Response */ public function update(FeedbackRequest $request, Feedback $feedback) { try { $attributes = $request->all(); $feedback->update($attributes); return $this->response->message(trans('messages.success.updated', ['Module' => trans('feedback::feedback.name')])) ->code(204) ->status('success') ->url(guard_url('feedback/feedback/' . $feedback->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('feedback/feedback/' . $feedback->getRouteKey())) ->redirect(); } } /** * Remove the feedback. * * @param Model $feedback * * @return Response */ public function destroy(FeedbackRequest $request, Feedback $feedback) { try { $feedback->delete(); return $this->response->message(trans('messages.success.deleted', ['Module' => trans('feedback::feedback.name')])) ->code(202) ->status('success') ->url(guard_url('feedback/feedback/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('feedback/feedback/' . $feedback->getRouteKey())) ->redirect(); } } /** * Remove multiple feedback. * * @param Model $feedback * * @return Response */ public function delete(FeedbackRequest $request, $type) { try { $ids = hashids_decode($request->input('ids')); if ($type == 'purge') { $this->repository->purge($ids); } else { $this->repository->delete($ids); } return $this->response->message(trans('messages.success.deleted', ['Module' => trans('feedback::feedback.name')])) ->status("success") ->code(202) ->url(guard_url('feedback/feedback')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/feedback/feedback')) ->redirect(); } } /** * Restore deleted feedback. * * @param Model $feedback * * @return Response */ public function restore(FeedbackRequest $request) { try { $ids = hashids_decode($request->input('ids')); $this->repository->restore($ids); return $this->response->message(trans('messages.success.restore', ['Module' => trans('feedback::feedback.name')])) ->status("success") ->code(202) ->url(guard_url('/feedback/feedback')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/feedback/feedback/')) ->redirect(); } } }