From 8f0fa0210748fb69ae7316925ed7962166b134a3 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 1 Apr 2015 09:12:49 +0200 Subject: [PATCH] Better redirection for new transactions. --- .../Controllers/TransactionController.php | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index 9f354fd3cc..c6b5cb039f 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -16,7 +16,7 @@ use Response; use Session; use View; use URL; - +use Log; /** * Class TransactionController @@ -62,6 +62,12 @@ class TransactionController extends Controller } Session::put('preFilled', $preFilled); + // put previous url in session if not redirect from store (not "create another"). + if(Session::get('transactions.create.fromStore') !== true) { + Session::put('transactions.create.url', URL::previous()); + } + Session::forget('transactions.create.fromStore'); + asort($piggies); @@ -165,6 +171,12 @@ class TransactionController extends Controller $preFilled['account_from_id'] = $transactions[1]->account->id; $preFilled['account_to_id'] = $transactions[0]->account->id; + // put previous url in session if not redirect from store (not "return_to_edit"). + if(Session::get('transactions.create.fromUpdate') !== true) { + Session::put('transactions.edit.url', URL::previous()); + } + Session::forget('transactions.create.fromUpdate'); + return View::make('transactions.edit', compact('journal', 'accounts', 'what', 'budgets', 'piggies', 'subTitle'))->with('data', $preFilled); } @@ -273,6 +285,7 @@ class TransactionController extends Controller */ public function store(JournalFormRequest $request, JournalRepositoryInterface $repository) { + $journalData = $request->getJournalData(); $journal = $repository->store($journalData); @@ -290,10 +303,13 @@ class TransactionController extends Controller Session::flash('success', 'New transaction "' . $journal->description . '" stored!'); if (intval(Input::get('create_another')) === 1) { + // set value so create routine will not overwrite URL: + Session::put('transactions.create.fromStore',true); return Redirect::route('transactions.create', $request->input('what'))->withInput(); } - return Redirect::to(URL::previous()); + // redirect to previous URL. + return Redirect::to(Session::get('transactions.create.url')); } @@ -316,11 +332,13 @@ class TransactionController extends Controller Session::flash('success', 'Transaction "' . e($journalData['description']) . '" updated.'); if (intval(Input::get('return_to_edit')) === 1) { + // set value so edit routine will not overwrite URL: + Session::put('transactions.create.fromUpdate',true); return Redirect::route('transactions.edit', $journal->id); } - - return Redirect::to(URL::previous()); + // redirect to previous URL. + return Redirect::to(Session::get('transactions.edit.url')); }