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