-
-
Notifications
You must be signed in to change notification settings - Fork 932
Closed
Description
API Platform version(s) affected: 4.1.20
Description
When using API Platform with Laravel and FormRequest validation, relation fields sent as IRIs (e.g. "/areas/{id}") are not denormalized to Eloquent models before the validation runs.
Instead, FormRequest receives the raw string. This differs from Symfony’s behavior, where relation IRIs are denormalized into Doctrine entities before Symfony Validator runs.
How to reproduce
- Have an API Platform Laravel resource with a relation to Area.
- Send JSON: { "area": "/areas/01abc123..." }
- In the FormRequest: dd($this->input('area'));
- Outputs "/areas/01abc123..."
Example Code
#[ApiResource(
operations: [
new Post(
rules: StoreSlotRequest::class,
denormalizationContext: [
'groups' => [
'slot:write'
],
],
)
]
)]
#[ApiProperty(property: 'area',
serialize: new Groups(['slot:write']
))]
class Slot extends Model{}
class StoreSlotRequest extends FormRequest
{
public function rules(): array
{
dd($this->input('area')); // "/areas/01abc123..."
}
}
Metadata
Metadata
Assignees
Labels
No labels