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

60 lines
1.9 KiB
PHP
Raw Normal View History

<?php
namespace FireflyIII\Http\Requests;
use Auth;
2015-02-09 00:23:39 -06:00
use Config;
use FireflyIII\Models\Account;
use Input;
/**
* Class AccountFormRequest
*
2015-05-10 01:08:07 -05:00
* @codeCoverageIgnore
* @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
return Auth::check();
}
2015-02-11 00:35:10 -06:00
/**
* @return array
*/
public function rules()
{
2015-04-03 15:54:21 -05:00
$accountRoles = join(',', array_keys(Config::get('firefly.accountRoles')));
$types = join(',', array_keys(Config::get('firefly.subTitlesByIdentifier')));
$ccPaymentTypes = join(',', array_keys(Config::get('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',
'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',
'what' => 'in:' . $types
];
}
}