Loosing data after clicking on custom action.
I have created custom action in for my table like,
Action::make('late_cancellation_at')
->requiresConfirmation()
->action(function (array $data, $record) {
$record->late_cancellation_at = now();
$record->status = 'cancelled';
$record->save();
})
->visible(fn (Model $record) => $record->status !== 'cancelled'),
Now when I click on this action all the data present in my table is getting lost.
Note: I have modified index in getPages() and parameters in getUrl like,
public static function getPages(): array
{
return [
'index' => Pages\ListCoachingSessions::route('{lineItem}'),
-------
-------
];
}
public static function getUrl(string $name = 'index', array $parameters = [], bool $isAbsolute = true, ?string $panel = null, ?Model $tenant = null): string
{
if (!isset($parameters['lineItem'])) {
if(request()->lineItem) {
$parameters['lineItem'] = request()->lineItem;
} else {
$url = request()->server('HTTP_REFERER');
$pattern = "/\/coaching-sessions\/([\w-]+)/";
preg_match($pattern, $url, $matches);
if(isset($matches[1])) {
$parameters['lineItem'] = $matches[1];
}
}
}
return parent::getUrl($name, $parameters, $isAbsolute, $panel, $tenant);
}
0 Replies