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