Skip to content

[Laravel] IRIs are not denormalized to Eloquent models before FormRequest validation #7337

@shahzaibtariqbutt

Description

@shahzaibtariqbutt

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

  1. Have an API Platform Laravel resource with a relation to Area.
  2. Send JSON: { "area": "/areas/01abc123..." }
  3. In the FormRequest: dd($this->input('area'));
  4. 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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions