code); Session::flash('success', $currency->name . ' is now the default currency.'); Cache::forget('FFCURRENCYSYMBOL'); Cache::forget('FFCURRENCYCODE'); return Redirect::route('currency.index'); } /** * @param TransactionCurrency $currency * * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View */ public function delete(TransactionCurrency $currency, CurrencyRepositoryInterface $repository) { if ($repository->countJournals($currency) > 0) { Session::flash('error', 'Cannot delete ' . e($currency->name) . ' because there are still transactions attached to it.'); return Redirect::route('currency.index'); } // put previous url in session Session::put('currency.delete.url', URL::previous()); return view('currency.delete', compact('currency')); } /** * @param TransactionCurrency $currency * * @return \Illuminate\Http\RedirectResponse */ public function destroy(TransactionCurrency $currency, CurrencyRepositoryInterface $repository) { if ($repository->countJournals($currency) > 0) { Session::flash('error', 'Cannot destroy ' . e($currency->name) . ' because there are still transactions attached to it.'); return Redirect::route('currency.index'); } Session::flash('success', 'Currency "' . e($currency->name) . '" deleted'); $currency->delete(); return Redirect::to(Session::get('currency.delete.url')); } /** * @param TransactionCurrency $currency * * @return \Illuminate\View\View */ public function edit(TransactionCurrency $currency) { $subTitleIcon = 'fa-pencil'; $subTitle = 'Edit currency "' . e($currency->name) . '"'; $currency->symbol = htmlentities($currency->symbol); // put previous url in session if not redirect from store (not "return_to_edit"). if (Session::get('currency.edit.fromUpdate') !== true) { Session::put('currency.edit.url', URL::previous()); } Session::forget('currency.edit.fromUpdate'); return view('currency.edit', compact('currency', 'subTitle', 'subTitleIcon')); } /** * @return \Illuminate\View\View */ public function index(CurrencyRepositoryInterface $repository) { $currencies = $repository->get(); $defaultCurrency = $repository->getCurrencyByPreference(Preferences::get('currencyPreference', 'EUR')); return view('currency.index', compact('currencies', 'defaultCurrency')); } /** * @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind. * * @return $this|\Illuminate\Http\RedirectResponse */ public function store(CurrencyFormRequest $request, CurrencyRepositoryInterface $repository) { $data = $request->getCurrencyData(); $currency = $repository->store($data); Session::flash('success', 'Currency "' . $currency->name . '" created'); if (intval(Input::get('create_another')) === 1) { Session::put('currency.create.fromStore', true); return Redirect::route('currency.create')->withInput(); } // redirect to previous URL. return Redirect::to(Session::get('currency.create.url')); } /** * @param TransactionCurrency $currency * * @return $this|\Illuminate\Http\RedirectResponse */ public function update(TransactionCurrency $currency, CurrencyFormRequest $request, CurrencyRepositoryInterface $repository) { $data = $request->getCurrencyData(); $currency = $repository->update($currency, $data); Session::flash('success', 'Currency "' . e($currency->name) . '" updated.'); if (intval(Input::get('return_to_edit')) === 1) { Session::put('currency.edit.fromUpdate', true); return Redirect::route('currency.edit', $currency->id); } // redirect to previous URL. return Redirect::to(Session::get('currency.edit.url')); } }