Replies: 2 comments
-
Using present seems correct to me, this was a bug which should be fixed with the release later today. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Just in case, nowadays, the required is still the default, but the namespace App\Data\Settings;
use App\Enums\Color;
use Spatie\LaravelData\Attributes\MergeValidationRules;
use Spatie\LaravelData\Attributes\Validation\Present;
use Spatie\LaravelData\Data;
#[MergeValidationRules]
final class SomeData extends Data
{
public function __construct(
public bool $enabled,
public ?Color $color,
/** @var \App\Enums\ColorShade[] */
#[Present]
public array $shades,
) {}
public static function rules(): array
{
return [
'shades.*' => [
'distinct',
],
];
}
} Without the attribute, a request with |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Current it seems there is no way to make a field optional without using the
|Optional
class... or the?
optional flag on property.I would like to validate an empty array, so:
I would like to change this to use
present
instead ofrequired
, but the#[Present]
doesn't work, the required is still applied.Changing to
array|Optional
works but then it will get optional object instead of empty array...It there a better way to allow an empty array instead of overwriting rules?
To be honest i thought
present
would be implied by default instead ofrequired
.For now what i did was i created a
PresentRuleInferrer
and removedRequiredRuleInferrer
, maybe that's a good approach, i can open a PR with that if you guys think it's a good approach.Beta Was this translation helpful? Give feedback.
All reactions