I'm using Spatie Laravel-data to create data objects to pass in and out of an API. I'm hitting an issue trying to create a DTO from a POST request - there are certain fields that won't be passed in for an INSERT, the obvious one being ID.
I'm failing validation each time, with the following error
{
"message": "The given data was invalid.",
"errors": {
"id": [
"The id field is required."
]
}
}
My DTO class follows these instructions and looks like this:
class MemberData extends Data
{
public function __construct(
public int|Optional $id,
#[Max(255)]
public string $first_name,
#[Max(255)]
public string $last_name,
)
{}
}
How can I get past validation without providing an ID? Or should I be creating a different DTO for an INSERT?