. */ declare(strict_types=1); namespace FireflyIII\Http\Requests; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; /** * @codeCoverageIgnore * Class BudgetFormRequest. */ class BudgetFormRequest extends Request { /** * @return bool */ public function authorize() { return auth()->check(); } /** * @return array */ public function getBudgetData(): array { return [ 'name' => $this->string('name'), 'active' => $this->boolean('active'), ]; } /** * @return array */ public function rules() { // fixed /** @var BudgetRepositoryInterface $repository */ $repository = app(BudgetRepositoryInterface::class); $nameRule = 'required|between:1,100|uniqueObjectForUser:budgets,name'; if (null !== $repository->findNull(intval($this->get('id')))) { $nameRule = 'required|between:1,100|uniqueObjectForUser:budgets,name,' . intval($this->get('id')); } return [ 'name' => $nameRule, 'active' => 'numeric|between:0,1', ]; } }