No use models directly.

This commit is contained in:
James Cole 2016-10-23 12:41:54 +02:00
parent a79a8c8874
commit 6a2f8fa9ee
5 changed files with 24 additions and 17 deletions

View File

@ -14,7 +14,7 @@ declare(strict_types = 1);
namespace FireflyIII\Http\Requests;
use Carbon\Carbon;
use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
/**
* Class AccountFormRequest
@ -60,13 +60,15 @@ class AccountFormRequest extends Request
*/
public function rules()
{
/** @var AccountRepositoryInterface $repository */
$repository = app(AccountRepositoryInterface::class);
$accountRoles = join(',', array_keys(config('firefly.accountRoles')));
$types = join(',', array_keys(config('firefly.subTitlesByIdentifier')));
$ccPaymentTypes = join(',', array_keys(config('firefly.ccTypes')));
$nameRule = 'required|min:1|uniqueAccountForUser';
$idRule = '';
if (Account::find($this->get('id'))) {
if (!is_null($repository->find(intval($this->get('id')))->id)) {
$idRule = 'belongsToUser:accounts';
$nameRule = 'required|min:1|uniqueAccountForUser:' . $this->get('id');
}

View File

@ -13,7 +13,7 @@ declare(strict_types = 1);
namespace FireflyIII\Http\Requests;
use FireflyIII\Models\Budget;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
/**
* Class BudgetFormRequest
@ -47,9 +47,10 @@ class BudgetFormRequest extends Request
*/
public function rules()
{
$nameRule = 'required|between:1,100|uniqueObjectForUser:budgets,name';
if (Budget::find($this->get('id'))) {
/** @var BudgetRepositoryInterface $repository */
$repository = app(BudgetRepositoryInterface::class);
$nameRule = 'required|between:1,100|uniqueObjectForUser:budgets,name';
if (!is_null($repository->find(intval($this->get('id')))->id)) {
$nameRule = 'required|between:1,100|uniqueObjectForUser:budgets,name,' . intval($this->get('id'));
}

View File

@ -13,7 +13,7 @@ declare(strict_types = 1);
namespace FireflyIII\Http\Requests;
use FireflyIII\Models\Category;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
/**
* Class CategoryFormRequest
@ -47,9 +47,10 @@ class CategoryFormRequest extends Request
*/
public function rules()
{
$nameRule = 'required|between:1,100|uniqueObjectForUser:categories,name';
if (Category::find($this->get('id'))) {
/** @var CategoryRepositoryInterface $repository */
$repository = app(CategoryRepositoryInterface::class);
$nameRule = 'required|between:1,100|uniqueObjectForUser:categories,name';
if (!is_null($repository->find(intval($this->get('id')))->id)) {
$nameRule = 'required|between:1,100|uniqueObjectForUser:categories,name,' . intval($this->get('id'));
}

View File

@ -13,7 +13,7 @@ declare(strict_types = 1);
namespace FireflyIII\Http\Requests;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
/**
* Class RuleFormRequest
@ -57,7 +57,8 @@ class RuleFormRequest extends Request
*/
public function rules()
{
/** @var RuleGroupRepositoryInterface $repository */
$repository = app(RuleGroupRepositoryInterface::class);
$validTriggers = array_keys(config('firefly.rule-triggers'));
$validActions = array_keys(config('firefly.rule-actions'));
@ -65,7 +66,7 @@ class RuleFormRequest extends Request
$contextActions = join(',', config('firefly.rule-actions-text'));
$titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title';
if (RuleGroup::find($this->get('id'))) {
if (!is_null($repository->find(intval($this->get('id')))->id)) {
$titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title,' . intval($this->get('id'));
}

View File

@ -13,7 +13,7 @@ declare(strict_types = 1);
namespace FireflyIII\Http\Requests;
use Carbon\Carbon;
use FireflyIII\Models\Tag;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
/**
* Class TagFormRequest
@ -68,9 +68,11 @@ class TagFormRequest extends Request
*/
public function rules()
{
$idRule = '';
$tagRule = 'required|min:1|uniqueObjectForUser:tags,tag';
if (Tag::find($this->get('id'))) {
/** @var TagRepositoryInterface $repository */
$repository = app(TagRepositoryInterface::class);
$idRule = '';
$tagRule = 'required|min:1|uniqueObjectForUser:tags,tag';
if (!is_null($repository->find(intval($this->get('id')))->id)) {
$idRule = 'belongsToUser:tags';
$tagRule = 'required|min:1|uniqueObjectForUser:tags,tag,' . $this->get('id');
}