Reordering new item on Repeater relationship throw error

When I add new item to the repeater and reordering, it throw error. This is not happened to existing item.
Repeater::make('shifts')
->relationship('shifts')
->orderColumn('sort')
->reorderable(true)
->schema([
TimePicker::make('start_time')
->required()
->native(false)
->seconds(false)
->minutesStep(30)
->live('onBlur')
->afterStateUpdated(function (Get $get, Set $set) {
$duration = $get('../../duration') ?? 0;
$time=Carbon::createFromFormat('Y-m-d H:i:s', $get('start_time'))->addMinute($duration);
$set('end_time', $time);
}),
TimePicker::make('end_time')
->required()
->native(false)
->seconds(false)
->minutesStep(30)
->rule('after:start_time'),
])
->addAction(function (FormAction $action) {
return $action
->label('Add Shift')
->action(function (Get $get, Set $set) {
$shifts = $get('shifts') ?? [];
if(count($shifts) > 0) {
$last = end($shifts);
$duration = $get('duration') ?? 0;
($last) ? $start = $last['end_time'] : $start = null;
$shifts[] = [
'start_time' => $start,
'end_time' => Carbon::createFromFormat('Y-m-d H:i:s', $last['end_time'])->addMinute($duration),
];
$set('shifts', $shifts);
} else {
$shifts[] = [
'start_time' => null,
'end_time' => null,
];
$set('shifts', $shifts);
}
});
}),
Repeater::make('shifts')
->relationship('shifts')
->orderColumn('sort')
->reorderable(true)
->schema([
TimePicker::make('start_time')
->required()
->native(false)
->seconds(false)
->minutesStep(30)
->live('onBlur')
->afterStateUpdated(function (Get $get, Set $set) {
$duration = $get('../../duration') ?? 0;
$time=Carbon::createFromFormat('Y-m-d H:i:s', $get('start_time'))->addMinute($duration);
$set('end_time', $time);
}),
TimePicker::make('end_time')
->required()
->native(false)
->seconds(false)
->minutesStep(30)
->rule('after:start_time'),
])
->addAction(function (FormAction $action) {
return $action
->label('Add Shift')
->action(function (Get $get, Set $set) {
$shifts = $get('shifts') ?? [];
if(count($shifts) > 0) {
$last = end($shifts);
$duration = $get('duration') ?? 0;
($last) ? $start = $last['end_time'] : $start = null;
$shifts[] = [
'start_time' => $start,
'end_time' => Carbon::createFromFormat('Y-m-d H:i:s', $last['end_time'])->addMinute($duration),
];
$set('shifts', $shifts);
} else {
$shifts[] = [
'start_time' => null,
'end_time' => null,
];
$set('shifts', $shifts);
}
});
}),
The error : Filament\Forms\ComponentContainer::getRawState(): Return value must be of type Illuminate\Contracts\Support\Arrayable|array, int returned
Solution:
Okay I solved this. The problem is because I am using action to modified the item, and missed how repeater populate their array. I just need to adjust 'key' for my newly added item. Here my updated code. ```php ->addAction(function (FormAction $action) { return $action ->label('Add Shift')...
Jump to solution
1 Reply
Solution
Dennyvik
Dennyvik2mo ago
Okay I solved this. The problem is because I am using action to modified the item, and missed how repeater populate their array. I just need to adjust 'key' for my newly added item. Here my updated code.
->addAction(function (FormAction $action) {
return $action
->label('Add Shift')
->icon('heroicon-s-plus-circle')
->action(function (Get $get, Set $set) {
$shifts = $get('shifts') ?? [];
$count = count($shifts);
if($count > 0) {
$last = end($shifts);
$duration = $get('duration') ?? 0;

($last) ? $start = $last['end_time'] : $start = null;
$end = Carbon::createFromFormat('Y-m-d H:i:s', $last['end_time'])->addMinute($duration);

$shifts["record-".$count+1] = [
'start_time' => $start,
'end_time' => (string) $end,
];
$set('shifts', $shifts);
} else {
$shifts["record-".$count+1] = [
'start_time' => null,
'end_time' => null,
];
$set('shifts', $shifts);
}
});
->addAction(function (FormAction $action) {
return $action
->label('Add Shift')
->icon('heroicon-s-plus-circle')
->action(function (Get $get, Set $set) {
$shifts = $get('shifts') ?? [];
$count = count($shifts);
if($count > 0) {
$last = end($shifts);
$duration = $get('duration') ?? 0;

($last) ? $start = $last['end_time'] : $start = null;
$end = Carbon::createFromFormat('Y-m-d H:i:s', $last['end_time'])->addMinute($duration);

$shifts["record-".$count+1] = [
'start_time' => $start,
'end_time' => (string) $end,
];
$set('shifts', $shifts);
} else {
$shifts["record-".$count+1] = [
'start_time' => null,
'end_time' => null,
];
$set('shifts', $shifts);
}
});
This part solve it : $shifts["record-".$count+1] =
Want results from more Discord servers?
Add your server