Skip to content

Sort repeatables with hasMany and uniqueField #6933

@RenautMestdagh

Description

@RenautMestdagh

Environment

  • Laravel Version: 11.28
  • Nova Version: 5.7
  • PHP Version: 8.3
  • Database Driver & Version: MySQL 8.0

Description

When using uniqueField in combination with asHasMany on a Repeater field, sorting repeatable items does not function as expected.
Because uniqueField prevents IDs from being regenerated, Nova is unable to determine the correct sort order.

At the moment, we are using a temporary workaround by adding a hidden sort field within our BaseBlock model, which we manually populate using the fillUsing method.


Steps to Reproduce

  1. Define a Repeater field as follows:
Repeater::make('Blocks')  
    ->asHasMany()  
    ->uniqueField('id')  
    ->repeatables([  
        Repeaters\TextBlock::make(),  
        Repeaters\ImageBlock::make(),  
    ]),
  1. Attempt to reorder the repeatable items in the Nova interface.
  2. Observe that the order does not persist as expected due to the use of uniqueField.

Expected Behavior

The repeater items should remain sortable and persist their order even when using uniqueField in combination with asHasMany.


Actual Behavior

Sorting is not functional, as the uniqueField prevents Nova from updating or tracking the order of repeatable items.


Workaround

We currently work around this limitation by including a hidden sort field in our base model and manually setting its value via fillUsing.

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