generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 250
Open
Description
✏️ Describe the bug
According to the documentation, validation happens before the object is created. However, when using a custom creaton method (fromX()
), validation is not called, when using validateAndCreate
.
↪️ To Reproduce
Provide us a pest test like this one which shows the problem:
it('cannot validate data with validateAndCreate and custom creation method', function () {
class BaseData extends Data
{
public function __construct(
public string $name,
) {
}
public function fromDummy(array $payload): static
{
return self::from($payload);
}
}
// Validation exception is not thrown, instead ArgumentCountError: Too few arguments
dd(BaseData::validateAndCreate([]));
});
✅ Expected behavior
Validation Exception is thrown
🖥️ Versions
Laravel Data: 4.15
PHP: 8.3
Metadata
Metadata
Assignees
Labels
No labels