Skip to content

feat: add attribute-based DTO validation - #304

Merged
techmahedy merged 3 commits into
doppar:4.xfrom
rrr63:attribute-validation
Sep 9, 2026
Merged

feat: add attribute-based DTO validation#304
techmahedy merged 3 commits into
doppar:4.xfrom
rrr63:attribute-validation

Conversation

@rrr63

@rrr63 rrr63 commented Sep 9, 2026

Copy link
Copy Markdown
Member

Added DTO validation constraints:

#[NotBlank]
#[StringType]
#[Integer]
#[Length]
#[Between]

Example :

final class BookData
{
    #[NotBlank]
    #[StringType]
    #[Length(max: 255)]
    public string $title;

    #[NotBlank]
    #[Integer]
    #[Between(min: 1, max: 10000)]
    public int $pages;

    #[NotBlank]
    #[StringType]
    #[Length(max: 255)]
    public string $author;

    #[NotBlank]
    #[Integer]
    #[Between(min: 1, max: 5)]
    public int $rating;
}
public function storeManual(
    #[BindPayload(strict: true, validate: true)]
    BookData $book,
) {
    Book::create($book->toArray());

    return redirect('/books');
}

@techmahedy

Copy link
Copy Markdown
Member

@rrr63 please write your phpdoc in this way
follow @doppar convention https://doppar.com/versions/3.x/contributions#phpdoc

@techmahedy techmahedy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rrr63 perfect

@techmahedy
techmahedy merged commit f418c39 into doppar:4.x Sep 9, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants