2015-02-07 18:15:15 -06:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace FireflyIII\Http\Requests;
|
|
|
|
|
|
|
|
use Auth;
|
2015-02-09 00:23:39 -06:00
|
|
|
use Config;
|
2015-02-14 07:25:29 -06:00
|
|
|
use FireflyIII\Models\Account;
|
|
|
|
use Input;
|
2015-02-07 18:15:15 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class AccountFormRequest
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Http\Requests
|
|
|
|
*/
|
|
|
|
class AccountFormRequest extends Request
|
|
|
|
{
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
2015-02-07 18:15:15 -06:00
|
|
|
public function authorize()
|
|
|
|
{
|
|
|
|
// Only allow logged in users
|
|
|
|
return Auth::check();
|
|
|
|
}
|
|
|
|
|
2015-02-11 00:35:10 -06:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2015-02-07 18:15:15 -06:00
|
|
|
public function rules()
|
|
|
|
{
|
2015-02-09 00:23:39 -06:00
|
|
|
$accountRoles = join(',', array_keys(Config::get('firefly.accountRoles')));
|
|
|
|
$types = join(',', array_keys(Config::get('firefly.subTitlesByIdentifier')));
|
|
|
|
|
2015-02-14 07:25:29 -06:00
|
|
|
$nameRule = 'required|between:1,100|uniqueForUser:accounts,name';
|
|
|
|
if (Account::find(Input::get('id'))) {
|
|
|
|
$nameRule = 'required|between:1,100';
|
|
|
|
}
|
|
|
|
|
2015-02-07 18:15:15 -06:00
|
|
|
return [
|
2015-02-14 07:25:29 -06:00
|
|
|
'name' => $nameRule,
|
2015-02-09 00:23:39 -06:00
|
|
|
'openingBalance' => 'numeric',
|
|
|
|
'openingBalanceDate' => 'date',
|
|
|
|
'accountRole' => 'in:' . $accountRoles,
|
|
|
|
'active' => 'boolean',
|
2015-02-11 00:35:10 -06:00
|
|
|
'balance_currency_id' => 'exists:transaction_currencies,id',
|
2015-02-09 00:23:39 -06:00
|
|
|
'what' => 'in:' . $types
|
2015-02-07 18:15:15 -06:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|