Call to undefined method Spatie\LaravelData\Support\Validation\ValidationContext::payload() #494
Answered
by
rubenvanassche
anuzpandey
asked this question in
Q&A
-
When I'm trying to get the payload property from ValidationContext in
My DTO class use Illuminate\Validation\Rule;
use Spatie\LaravelData\Data;
use Spatie\LaravelData\Support\Validation\ValidationContext;
class UserRequestData extends Data
{
public function __construct(
// ... other fields
public readonly string $email,
public readonly ?string $role_id,
public readonly ?array $permission_ids,
public ?string $disabled_at,
) {
$this->disabled_at = $disabled_at === 'on' ? now()->toDateTimeString() : NULL;
}
public static function rules(ValidationContext $context): array
{
return [
// ... other fields
'email' => ['required', 'email', 'unique:users,email,' . $context->payload(['user_id'])],
'role_id' => [
Rule::requiredIf($context->payload(['permission_ids'])),
'bail'
],
'permission_ids' => ['nullable', 'array'],
'disabled_at' => ['nullable'],
];
}
} And Is it a good place for me to override the value of Thank you in advence. |
Beta Was this translation helpful? Give feedback.
Answered by
rubenvanassche
Jul 6, 2023
Replies: 2 comments
-
Payload is a property, not a method. Constructor looks fine to me to set a default. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
anuzpandey
-
Oh okay. My bad. Sorry. Thank you so much. |
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
Payload is a property, not a method.
Constructor looks fine to me to set a default.