Files
firefly-iii/app/Http/Requests/RuleGroupFormRequest.php

64 lines
1.5 KiB
PHP
Raw Normal View History

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