. */ declare(strict_types=1); namespace FireflyIII\Http\Requests; use FireflyIII\Repositories\Category\CategoryRepositoryInterface; /** * Class CategoryFormRequest. */ class CategoryFormRequest extends Request { /** * @return bool */ public function authorize() { // Only allow logged in users return auth()->check(); } /** * @return array */ public function getCategoryData(): array { return [ 'name' => $this->string('name'), ]; } /** * @return array */ public function rules() { /** @var CategoryRepositoryInterface $repository */ $repository = app(CategoryRepositoryInterface::class); $nameRule = 'required|between:1,100|uniqueObjectForUser:categories,name'; if (null !== $repository->findNull($this->integer('id'))) { $nameRule = 'required|between:1,100|uniqueObjectForUser:categories,name,' . $this->integer('id'); } // fixed return [ 'name' => $nameRule, ]; } }