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