From c37ade8f5b40117ac897e0a50cf0eb9ecc576072 Mon Sep 17 00:00:00 2001 From: James Cole Date: Thu, 24 Aug 2017 19:42:23 +0200 Subject: [PATCH] Catch link error. --- .../Transaction/LinkController.php | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/Transaction/LinkController.php b/app/Http/Controllers/Transaction/LinkController.php index 09036ea562..0b560c78c8 100644 --- a/app/Http/Controllers/Transaction/LinkController.php +++ b/app/Http/Controllers/Transaction/LinkController.php @@ -83,13 +83,6 @@ class LinkController extends Controller return redirect(strval(session('journal_links.delete.uri'))); } - public function switch(LinkTypeRepositoryInterface $repository, TransactionJournalLink $link) { - - $repository->switchLink($link); - - return redirect(URL::previous()); - } - /** * @param JournalLinkRequest $request * @param LinkTypeRepositoryInterface $repository @@ -127,8 +120,14 @@ class LinkController extends Controller $linkJournalId = intval($request->string('link_other')); } + $opposing = $journalRepository->find($linkJournalId); - $result = $repository->findLink($journal, $opposing); + if (is_null($opposing->id)) { + Session::flash('error', trans('firefly.invalid_link_data')); + + return redirect(route('transactions.show', $journal->id)); + } + $result = $repository->findLink($journal, $opposing); if ($result) { Session::flash('error', trans('firefly.journals_error_linked')); @@ -155,4 +154,12 @@ class LinkController extends Controller return redirect(route('transactions.show', $journal->id)); } + public function switch(LinkTypeRepositoryInterface $repository, TransactionJournalLink $link) + { + + $repository->switchLink($link); + + return redirect(URL::previous()); + } + } \ No newline at end of file