© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•12mo ago
DeathSummon

Filament Repeater: How to Create Multiple Records from a Single Entry?

I'm running into an issue with Filament’s repeater field and could use some help.

My Use Case:
I have a repeater with two fields in each item: one field lets the user select an item (e.g., "Item A") and another field lets them specify a quantity (e.g., 3). My goal is that a single repeater item should ultimately create multiple related records. For example, if a user selects "Item A" with quantity 3, I want to create an array like this:
[
    ['item' => 'A'],
    ['item' => 'A'],
    ['item' => 'A'],
]
[
    ['item' => 'A'],
    ['item' => 'A'],
    ['item' => 'A'],
]

My Code:
Repeater::make('cartonTransactions')
    ->relationship() // Relationship is set up correctly
    ->schema([
        Select::make('item')
            ->label('Item')
            ->options(Item::pluck('name', 'id'))
            ->required(),
        TextInput::make('quantity')
            ->numeric()
            ->minValue(1)
            ->required(),
    ])
    ->mutateRelationshipDataBeforeCreateUsing(function (array $data): array {
        // I want to create multiple records based on the quantity field.
        $quantity = (int) $data['quantity'];
        $item = $data['item'];

        $records = [];
        for ($i = 0; $i < $quantity; $i++) {
            $records[] = [
                'item' => $item,
            ];
        }
        // Returning an array of arrays instead of a single associative array.
        return $records;
    });
Repeater::make('cartonTransactions')
    ->relationship() // Relationship is set up correctly
    ->schema([
        Select::make('item')
            ->label('Item')
            ->options(Item::pluck('name', 'id'))
            ->required(),
        TextInput::make('quantity')
            ->numeric()
            ->minValue(1)
            ->required(),
    ])
    ->mutateRelationshipDataBeforeCreateUsing(function (array $data): array {
        // I want to create multiple records based on the quantity field.
        $quantity = (int) $data['quantity'];
        $item = $data['item'];

        $records = [];
        for ($i = 0; $i < $quantity; $i++) {
            $records[] = [
                'item' => $item,
            ];
        }
        // Returning an array of arrays instead of a single associative array.
        return $records;
    });

The Problem:
Filament’s callback is designed to return a single associative array per repeater item. Because I'm returning an array of arrays, only the first record is being processed. This results in an error when saving the relationship.
The Error I Received:
SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed
How can I resolve this?
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

How to link to a resource from a repeater entry?
FilamentFFilament / ❓┊help
3y ago
Multiple clicks create duplicate entry
FilamentFFilament / ❓┊help
2y ago
Multiple filament (?) components in a single page
FilamentFFilament / ❓┊help
9mo ago
Create multiple records at once
FilamentFFilament / ❓┊help
3y ago