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