repository = $currency; $this->repository ->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class) ->pushCriteria(\Litecms\CurrencySetting\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(\Litecms\CurrencySetting\Repositories\Presenter\CurrencyPresenter::class) ->$function(); } $currencies = $this->repository->paginate(); return $this->response->title(trans('currency_setting::currency.names')) ->view('currency_setting::currency.index', true) ->data(compact('currencies')) ->output(); } /** * Display currency. * * @param Request $request * @param Model $currency * * @return Response */ public function show(CurrencyRequest $request, Currency $currency) { if ($currency->exists) { $view = 'currency_setting::currency.show'; } else { $view = 'currency_setting::currency.new'; } return $this->response->title(trans('app.view') . ' ' . trans('currency_setting::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->title(trans('app.new') . ' ' . trans('currency_setting::currency.name')) ->view('currency_setting::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('currency_setting::currency.name')])) ->code(204) ->status('success') ->url(guard_url('currency_setting/currency/' . $currency->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('/currency_setting/currency')) ->redirect(); } } /** * Show currency for editing. * * @param Request $request * @param Model $currency * * @return Response */ public function edit(CurrencyRequest $request, Currency $currency) { return $this->response->title(trans('app.edit') . ' ' . trans('currency_setting::currency.name')) ->view('currency_setting::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('currency_setting::currency.name')])) ->code(204) ->status('success') ->url(guard_url('currency_setting/currency/' . $currency->getRouteKey())) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('currency_setting/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('currency_setting::currency.name')])) ->code(202) ->status('success') ->url(guard_url('currency_setting/currency/0')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->code(400) ->status('error') ->url(guard_url('currency_setting/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('currency_setting::currency.name')])) ->status("success") ->code(202) ->url(guard_url('currency_setting/currency')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/currency_setting/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('currency_setting::currency.name')])) ->status("success") ->code(202) ->url(guard_url('/currency_setting/currency')) ->redirect(); } catch (Exception $e) { return $this->response->message($e->getMessage()) ->status("error") ->code(400) ->url(guard_url('/currency_setting/currency/')) ->redirect(); } } }