Skip to content

Firefly III: a personal finances manager

More for #339

James Colea8a8afc2be92
diff --git a/app/Http/Controllers/AttachmentController.php b/app/Http/Controllers/AttachmentController.php
index 7063877e88..05e71a9a8f 100644
--- a/app/Http/Controllers/AttachmentController.php
+++ b/app/Http/Controllers/AttachmentController.php
@@ -164,14 +164,8 @@ class AttachmentController extends Controller
*/
public function update(AttachmentFormRequest $request, AttachmentRepositoryInterface $repository, Attachment $attachment)
{
-
- $attachmentData = [
- 'title' => $request->input('title'),
- 'description' => $request->input('description'),
- 'notes' => $request->input('notes'),
- ];
-
- $repository->update($attachment, $attachmentData);
+ $data = $request->getAttachmentData();
+ $repository->update($attachment, $data);
Session::flash('success', strval(trans('firefly.attachment_updated', ['name' => $attachment->filename])));
Preferences::mark();
diff --git a/app/Http/Controllers/BudgetController.php b/app/Http/Controllers/BudgetController.php
index 93d9a35261..439dfb6d8b 100644
--- a/app/Http/Controllers/BudgetController.php
+++ b/app/Http/Controllers/BudgetController.php
@@ -359,11 +359,8 @@ class BudgetController extends Controller
*/
public function store(BudgetFormRequest $request, BudgetRepositoryInterface $repository)
{
- $budgetData = [
- 'name' => $request->input('name'),
- 'user' => auth()->user()->id,
- ];
- $budget = $repository->store($budgetData);
+ $data = $request->getBudgetData();
+ $budget = $repository->store($data);
Session::flash('success', strval(trans('firefly.stored_new_budget', ['name' => e($budget->name)])));
Preferences::mark();
@@ -389,12 +386,8 @@ class BudgetController extends Controller
*/
public function update(BudgetFormRequest $request, BudgetRepositoryInterface $repository, Budget $budget)
{
- $budgetData = [
- 'name' => $request->input('name'),
- 'active' => intval($request->input('active')) == 1,
- ];
-
- $repository->update($budget, $budgetData);
+ $data = $request->getBudgetData();
+ $repository->update($budget, $data);
Session::flash('success', strval(trans('firefly.updated_budget', ['name' => e($budget->name)])));
Preferences::mark();
diff --git a/app/Http/Requests/AccountFormRequest.php b/app/Http/Requests/AccountFormRequest.php
index 1264cbc3c7..1968e5bdca 100644
--- a/app/Http/Requests/AccountFormRequest.php
+++ b/app/Http/Requests/AccountFormRequest.php
@@ -37,7 +37,7 @@ class AccountFormRequest extends Request
/**
* @return array
*/
- public function getAccountDate(): array
+ public function getAccountData(): array
{
return [
'name' => trim($this->input('name')),
diff --git a/app/Http/Requests/AttachmentFormRequest.php b/app/Http/Requests/AttachmentFormRequest.php
index 78cbda523b..16028cab37 100644
--- a/app/Http/Requests/AttachmentFormRequest.php
+++ b/app/Http/Requests/AttachmentFormRequest.php
@@ -30,6 +30,18 @@ class AttachmentFormRequest extends Request
return auth()->check();
}
+ /**
+ * @return array
+ */
+ public function getAttachmentData(): array
+ {
+ return [
+ 'title' => trim($this->input('title')),
+ 'description' => trim($this->input('description')),
+ 'notes' => trim($this->input('notes')),
+ ];
+ }
+
/**
* @return array
*/
diff --git a/app/Http/Requests/BudgetFormRequest.php b/app/Http/Requests/BudgetFormRequest.php
index 6d1b8a02b1..503e54be76 100644
--- a/app/Http/Requests/BudgetFormRequest.php
+++ b/app/Http/Requests/BudgetFormRequest.php
@@ -29,10 +29,21 @@ class BudgetFormRequest extends Request
*/
public function authorize()
{
- // Only allow logged in users
return auth()->check();
}
+ /**
+ * @return array
+ */
+ public function getBudgetData(): array
+ {
+ return [
+ 'name' => trim($this->input('name')),
+ 'user' => auth()->user()->id,
+ 'active' => intval($this->input('active')) == 1,
+ ];
+ }
+
/**
* @return array
*/
diff --git a/resources/views/budgets/create.twig b/resources/views/budgets/create.twig
index de276f2920..24f47d7ac2 100644
--- a/resources/views/budgets/create.twig
+++ b/resources/views/budgets/create.twig
@@ -8,6 +8,7 @@
<form method="POST" action="{{ route('budgets.store') }}" accept-charset="UTF-8" class="form-horizontal" id="store">
<input name="_token" type="hidden" value="{{ csrf_token() }}">
+ <input name="active" type="hidden" value="1">
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-12">