You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note: this is an oversimplification to show the issues I have been experiencing with exclude , exclude_with, and other exclude... rules in Data objects.
public function store(EmailAddressData $emailAddressData)
{
$theData = $emailAddressData->toArray();
dd($theData);
}
the EmailAddressData DTO:
<?php
namespace App\Data;
use Spatie\LaravelData\Data;
class EmailAddressData extends Data
{
public function __construct(
public readonly ?string $email,
public readonly ?string $email_md5,
) {}
public static function rules()
{
return [
'email' => ['email'],
'email_md5' => ['exclude_with:email'],
];
}
}
At the moment validation works with both the mapped and non mapped names, but the mapped version name is always taken when present. We'll need to make some changes here to always use the data object property name. We'll do this in v4 because it's breaking stuff. At the moment the validator returns the mapped name but we need the non mapped version at this point to continue.
Note: this is an oversimplification to show the issues I have been experiencing with exclude , exclude_with, and other exclude... rules in Data objects.
Given the form:
the route:
the EmailAddressController store function:
the EmailAddressData DTO:
dd($theData); shows:
Note that email_md5 is not excluded. Even using the email_md5 rule as exclude fails to exclude the email_md5 from the validated data.
However, using the exact same rules in a FormRequest does exclude the md5_email from the validated data:
dd($theData) shows:
The text was updated successfully, but these errors were encountered: