firefly-iii/app/Http/Requests/BillUpdateRequest.php

87 lines
2.8 KiB
PHP
Raw Normal View History

2015-02-25 08:19:14 -06:00
<?php
/**
2020-06-30 12:06:05 -05:00
* BillUpdateRequest.php
2020-01-31 00:32:04 -06:00
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2017-10-21 01:40:00 -05:00
*
* This program is distributed in the hope that it will be useful,
2017-10-21 01:40:00 -05:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2017-10-21 01:40:00 -05:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2017-03-24 09:15:12 -05:00
declare(strict_types=1);
2015-02-25 08:19:14 -06:00
namespace FireflyIII\Http\Requests;
2018-08-07 12:24:07 -05:00
use FireflyIII\Models\Bill;
2015-02-25 08:19:14 -06:00
/**
2020-06-30 12:06:05 -05:00
* Class BillUpdateRequest.
2015-02-25 08:19:14 -06:00
*/
2020-06-30 12:06:05 -05:00
class BillUpdateRequest extends Request
2015-02-25 08:19:14 -06:00
{
/**
2018-07-22 01:10:16 -05:00
* Verify the request.
*
2015-02-25 08:19:14 -06:00
* @return bool
*/
2018-07-08 05:28:42 -05:00
public function authorize(): bool
2015-02-25 08:19:14 -06:00
{
// Only allow logged in users
2016-09-16 05:07:45 -05:00
return auth()->check();
2015-02-25 08:19:14 -06:00
}
2015-03-29 04:51:26 -05:00
/**
2018-07-22 01:10:16 -05:00
* Returns the data required by the controller.
*
2015-03-29 04:51:26 -05:00
* @return array
*/
2018-07-08 05:28:42 -05:00
public function getBillData(): array
2015-03-29 04:51:26 -05:00
{
return [
2018-08-19 12:31:21 -05:00
'name' => $this->string('name'),
'amount_min' => $this->string('amount_min'),
'currency_id' => $this->integer('transaction_currency_id'),
'currency_code' => '',
'amount_max' => $this->string('amount_max'),
'date' => $this->date('date'),
'repeat_freq' => $this->string('repeat_freq'),
'skip' => $this->integer('skip'),
2019-09-19 23:14:08 -05:00
'notes' => $this->nlString('notes'),
2018-08-19 12:31:21 -05:00
'active' => $this->boolean('active'),
2020-06-30 12:06:05 -05:00
'object_group' => $this->string('object_group'),
2015-03-29 04:51:26 -05:00
];
}
2015-02-25 08:19:14 -06:00
/**
2018-07-22 01:10:16 -05:00
* Rules for this request.
*
2015-02-25 08:19:14 -06:00
* @return array
*/
2018-07-02 13:17:50 -05:00
public function rules(): array
2015-02-25 08:19:14 -06:00
{
2018-08-07 12:24:07 -05:00
/** @var Bill $bill */
$bill = $this->route()->parameter('bill');
2020-06-30 12:06:05 -05:00
return [
'name' => sprintf('required|between:1,255|uniqueObjectForUser:bills,name,%d', $bill->id),
2019-09-09 11:55:23 -05:00
'amount_min' => 'required|numeric|more:0|max:1000000000',
'amount_max' => 'required|numeric|more:0|max:1000000000',
2018-04-08 09:27:52 -05:00
'transaction_currency_id' => 'required|exists:transaction_currencies,id',
'date' => 'required|date',
'repeat_freq' => 'required|in:weekly,monthly,quarterly,half-year,yearly',
'skip' => 'required|between:0,31',
2018-06-24 09:17:42 -05:00
'active' => 'boolean',
2015-02-25 08:19:14 -06:00
];
}
2015-03-29 01:14:32 -05:00
}