From 7578ec680130139d4eb4de62c332af9d256e5e06 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 1 Apr 2015 09:40:19 +0200 Subject: [PATCH] Fix redirections in budget. --- app/Http/Controllers/BudgetController.php | 30 ++++++++++++++++--- .../Controllers/TransactionController.php | 8 ++--- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php index 79247f0397..066edb7fc8 100644 --- a/app/Http/Controllers/BudgetController.php +++ b/app/Http/Controllers/BudgetController.php @@ -13,7 +13,7 @@ use Redirect; use Response; use Session; use View; - +use URL; /** * Class BudgetController * @@ -49,6 +49,12 @@ class BudgetController extends Controller */ public function create() { + // put previous url in session if not redirect from store (not "create another"). + if (Session::get('budgets.create.fromStore') !== true) { + Session::put('budgets.create.url', URL::previous()); + } + Session::forget('budgets.create.fromStore'); + return view('budgets.create')->with('subTitle', 'Create a new budget'); } @@ -61,6 +67,9 @@ class BudgetController extends Controller { $subTitle = 'Delete budget' . e($budget->name) . '"'; + // put previous url in session + Session::put('budgets.delete.url', URL::previous()); + return view('budgets.delete', compact('budget', 'subTitle')); } @@ -75,9 +84,11 @@ class BudgetController extends Controller $name = $budget->name; $repository->destroy($budget); + + Session::flash('success', 'The budget "' . e($name) . '" was deleted.'); - return Redirect::route('budgets.index'); + return Redirect::to(Session::get('budgets.delete.url')); } /** @@ -89,6 +100,12 @@ class BudgetController extends Controller { $subTitle = 'Edit budget "' . e($budget->name) . '"'; + // put previous url in session if not redirect from store (not "return_to_edit"). + if (Session::get('budgets.edit.fromUpdate') !== true) { + Session::put('budgets.edit.url', URL::previous()); + } + Session::forget('budgets.edit.fromUpdate'); + return view('budgets.edit', compact('budget', 'subTitle')); } @@ -172,10 +189,13 @@ class BudgetController extends Controller Session::flash('success', 'New budget "' . $budget->name . '" stored!'); if (intval(Input::get('create_another')) === 1) { + // set value so create routine will not overwrite URL: + Session::put('budgets.create.fromStore', true); return Redirect::route('budgets.create')->withInput(); } - return Redirect::route('budgets.index'); + // redirect to previous URL. + return Redirect::to(Session::get('budgets.create.url')); } @@ -219,7 +239,9 @@ class BudgetController extends Controller Session::flash('success', 'Budget "' . $budget->name . '" updated.'); if (intval(Input::get('return_to_edit')) === 1) { - return Redirect::route('budgets.edit', $budget->id); + // set value so edit routine will not overwrite URL: + Session::put('budgets.edit.fromUpdate', true); + return Redirect::route('budgets.edit', $budget->id)->withInput(['return_to_edit' => 1]); } return Redirect::route('budgets.index'); diff --git a/app/Http/Controllers/TransactionController.php b/app/Http/Controllers/TransactionController.php index 17d4b2ae57..e8300109ad 100644 --- a/app/Http/Controllers/TransactionController.php +++ b/app/Http/Controllers/TransactionController.php @@ -163,10 +163,10 @@ class TransactionController extends Controller $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) { + if (Session::get('transactions.edit.fromUpdate') !== true) { Session::put('transactions.edit.url', URL::previous()); } - Session::forget('transactions.create.fromUpdate'); + Session::forget('transactions.edit.fromUpdate'); return View::make('transactions.edit', compact('journal', 'accounts', 'what', 'budgets', 'piggies', 'subTitle'))->with('data', $preFilled); @@ -325,9 +325,9 @@ class TransactionController extends Controller if (intval(Input::get('return_to_edit')) === 1) { // set value so edit routine will not overwrite URL: - Session::put('transactions.create.fromUpdate', true); + Session::put('transactions.edit.fromUpdate', true); - return Redirect::route('transactions.edit', $journal->id)->withInput(['return_to_edit' => intval(Input::get('return_to_edit'))]); + return Redirect::route('transactions.edit', $journal->id)->withInput(['return_to_edit' => 1]); } // redirect to previous URL.