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