From 12e81364a025a85bf97ae0c5a8b789f614c40225 Mon Sep 17 00:00:00 2001 From: James Cole Date: Thu, 19 Mar 2020 09:01:35 +0100 Subject: [PATCH] Make sure all controllers can store attachment when creating models #2828 --- app/Http/Controllers/Account/EditController.php | 3 +-- app/Http/Controllers/Budget/CreateController.php | 9 +++++++++ app/Http/Controllers/Category/CreateController.php | 9 +++++++++ app/Http/Controllers/PiggyBankController.php | 10 ++++++++++ app/Http/Controllers/TagController.php | 10 ++++++++++ 5 files changed, 39 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Account/EditController.php b/app/Http/Controllers/Account/EditController.php index 66d0620f55..19ea840809 100644 --- a/app/Http/Controllers/Account/EditController.php +++ b/app/Http/Controllers/Account/EditController.php @@ -190,8 +190,7 @@ class EditController extends Controller $request->session()->flash('success', (string) trans('firefly.updated_account', ['name' => $account->name])); app('preferences')->mark(); - // store new attachments - // store attachment(s): + // store new attachment(s): /** @var array $files */ $files = $request->hasFile('attachments') ? $request->file('attachments') : null; $this->attachments->saveAttachmentsForModel($account, $files); diff --git a/app/Http/Controllers/Budget/CreateController.php b/app/Http/Controllers/Budget/CreateController.php index 111491c5e7..a802c30134 100644 --- a/app/Http/Controllers/Budget/CreateController.php +++ b/app/Http/Controllers/Budget/CreateController.php @@ -129,6 +129,15 @@ class CreateController extends Controller $request->session()->flash('success', (string) trans('firefly.stored_new_budget', ['name' => $budget->name])); app('preferences')->mark(); + // store attachment(s): + /** @var array $files */ + $files = $request->hasFile('attachments') ? $request->file('attachments') : null; + $this->attachments->saveAttachmentsForModel($budget, $files); + + if (count($this->attachments->getMessages()->get('attachments')) > 0) { + $request->session()->flash('info', $this->attachments->getMessages()->get('attachments')); // @codeCoverageIgnore + } + $redirect = redirect($this->getPreviousUri('budgets.create.uri')); if (1 === (int) $request->get('create_another')) { diff --git a/app/Http/Controllers/Category/CreateController.php b/app/Http/Controllers/Category/CreateController.php index a8da02a46c..7e019fc43f 100644 --- a/app/Http/Controllers/Category/CreateController.php +++ b/app/Http/Controllers/Category/CreateController.php @@ -101,6 +101,15 @@ class CreateController extends Controller $request->session()->flash('success', (string) trans('firefly.stored_category', ['name' => $category->name])); app('preferences')->mark(); + // store attachment(s): + /** @var array $files */ + $files = $request->hasFile('attachments') ? $request->file('attachments') : null; + $this->attachments->saveAttachmentsForModel($category, $files); + + if (count($this->attachments->getMessages()->get('attachments')) > 0) { + $request->session()->flash('info', $this->attachments->getMessages()->get('attachments')); // @codeCoverageIgnore + } + $redirect = redirect(route('categories.index')); if (1 === (int) $request->get('create_another')) { // @codeCoverageIgnoreStart diff --git a/app/Http/Controllers/PiggyBankController.php b/app/Http/Controllers/PiggyBankController.php index 59f05f36cd..69c32ad53f 100644 --- a/app/Http/Controllers/PiggyBankController.php +++ b/app/Http/Controllers/PiggyBankController.php @@ -451,6 +451,16 @@ class PiggyBankController extends Controller session()->flash('success', (string) trans('firefly.stored_piggy_bank', ['name' => $piggyBank->name])); app('preferences')->mark(); + // store attachment(s): + /** @var array $files */ + $files = $request->hasFile('attachments') ? $request->file('attachments') : null; + $this->attachments->saveAttachmentsForModel($piggyBank, $files); + + if (count($this->attachments->getMessages()->get('attachments')) > 0) { + $request->session()->flash('info', $this->attachments->getMessages()->get('attachments')); // @codeCoverageIgnore + } + + $redirect = redirect($this->getPreviousUri('piggy-banks.create.uri')); if (1 === (int) $request->get('create_another')) { diff --git a/app/Http/Controllers/TagController.php b/app/Http/Controllers/TagController.php index 6ebd1c6499..50d0969ed3 100644 --- a/app/Http/Controllers/TagController.php +++ b/app/Http/Controllers/TagController.php @@ -316,6 +316,16 @@ class TagController extends Controller session()->flash('success', (string) trans('firefly.created_tag', ['tag' => $data['tag']])); app('preferences')->mark(); + // store attachment(s): + /** @var array $files */ + $files = $request->hasFile('attachments') ? $request->file('attachments') : null; + $this->attachments->saveAttachmentsForModel($result, $files); + + if (count($this->attachments->getMessages()->get('attachments')) > 0) { + $request->session()->flash('info', $this->attachments->getMessages()->get('attachments')); // @codeCoverageIgnore + } + + $redirect = redirect($this->getPreviousUri('tags.create.uri')); if (1 === (int) $request->get('create_another')) { // @codeCoverageIgnoreStart