2016-01-13 11:34:56 -06:00
|
|
|
<?php
|
2016-05-20 05:41:23 -05:00
|
|
|
/**
|
|
|
|
* RuleGroupFormRequest.php
|
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
|
|
*
|
2016-10-04 23:52:15 -05:00
|
|
|
* 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-05-20 05:41:23 -05:00
|
|
|
*/
|
|
|
|
|
2016-02-05 05:08:25 -06:00
|
|
|
declare(strict_types = 1);
|
2016-01-13 11:34:56 -06:00
|
|
|
|
|
|
|
namespace FireflyIII\Http\Requests;
|
|
|
|
|
2016-10-23 05:10:22 -05:00
|
|
|
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
2016-01-13 11:34:56 -06:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class RuleGroupFormRequest
|
|
|
|
*
|
2016-02-04 00:28:39 -06:00
|
|
|
*
|
2016-01-13 11:34:56 -06:00
|
|
|
* @package FireflyIII\Http\Requests
|
|
|
|
*/
|
|
|
|
class RuleGroupFormRequest extends Request
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function authorize()
|
|
|
|
{
|
|
|
|
// Only allow logged in users
|
2016-09-16 05:07:45 -05:00
|
|
|
return auth()->check();
|
2016-01-13 11:34:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2016-10-23 05:10:22 -05:00
|
|
|
public function getRuleGroupData(): array
|
2016-01-13 11:34:56 -06:00
|
|
|
{
|
2016-10-23 05:10:22 -05:00
|
|
|
return [
|
2017-01-21 01:32:23 -06:00
|
|
|
'title' => $this->string('title'),
|
|
|
|
'description' => $this->string('description'),
|
2016-10-23 05:10:22 -05:00
|
|
|
];
|
|
|
|
}
|
2016-01-13 11:34:56 -06:00
|
|
|
|
2016-10-23 05:10:22 -05:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function rules()
|
|
|
|
{
|
|
|
|
/** @var RuleGroupRepositoryInterface $repository */
|
|
|
|
$repository = app(RuleGroupRepositoryInterface::class, [auth()->user()]);
|
|
|
|
$titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title';
|
|
|
|
if (!is_null($repository->find(intval($this->get('id')))->id)) {
|
|
|
|
$titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title,' . intval($this->get('id'));
|
2016-01-13 11:34:56 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
2016-01-15 16:12:52 -06:00
|
|
|
'title' => $titleRule,
|
2016-01-13 11:34:56 -06:00
|
|
|
'description' => 'between:1,5000',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|