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

70 lines
2.2 KiB
PHP
Raw Normal View History

<?php
/**
* AccountFormRequest.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
*/
2016-02-05 05:08:25 -06:00
declare(strict_types = 1);
namespace FireflyIII\Http\Requests;
use FireflyIII\Models\Account;
use Input;
/**
* Class AccountFormRequest
*
2016-02-04 00:28:39 -06:00
*
* @package FireflyIII\Http\Requests
*/
class AccountFormRequest extends Request
{
2015-02-11 00:35:10 -06:00
/**
* @return bool
*/
public function authorize()
{
// Only allow logged in users
2016-09-16 05:07:45 -05:00
return auth()->check();
}
2015-02-11 00:35:10 -06:00
/**
* @return array
*/
public function rules()
{
2016-04-26 14:40:15 -05:00
$accountRoles = join(',', array_keys(config('firefly.accountRoles')));
$types = join(',', array_keys(config('firefly.subTitlesByIdentifier')));
$ccPaymentTypes = join(',', array_keys(config('firefly.ccTypes')));
2015-02-09 00:23:39 -06:00
$nameRule = 'required|min:1|uniqueAccountForUser';
$idRule = '';
if (Account::find(Input::get('id'))) {
$idRule = 'belongsToUser:accounts';
$nameRule = 'required|min:1|uniqueAccountForUser:' . Input::get('id');
}
return [
'id' => $idRule,
'name' => $nameRule,
'openingBalance' => 'numeric',
'iban' => 'iban',
'virtualBalance' => 'numeric',
'openingBalanceDate' => 'date',
2016-02-10 23:40:06 -06:00
'accountNumber' => 'between:1,255|uniqueAccountNumberForUser',
'accountRole' => 'in:' . $accountRoles,
'active' => 'boolean',
'ccType' => 'in:' . $ccPaymentTypes,
'ccMonthlyPaymentDate' => 'date',
'amount_currency_id_openingBalance' => 'exists:transaction_currencies,id',
'amount_currency_id_virtualBalance' => 'exists:transaction_currencies,id',
2016-01-15 16:12:52 -06:00
'what' => 'in:' . $types,
];
}
}