Edit page - previous and next actions

Finally made something working. I just want to know if there's a better solution and if I access the things right for the "Edit" page?
protected function getActions(): array
{
$next_record = Order::select('id')->where('id', '>', $this->record->id)->orderBy('id')->first();
$previous_record = Order::select('id')->where('id', '<', $this->record->id)->orderBy('id','desc')->first();

return [
Actions\Action::make('previous')
->label('')
->icon('heroicon-s-chevron-left')
->color('secondary')
->url(fn () => $previous_record ? OrderResource::getUrl('edit', ['record' => $previous_record]) : NULL)
->visible(fn () => $previous_record ?? FALSE),
Actions\Action::make('next')
->label('')
->icon('heroicon-s-chevron-right')
->color('secondary')
->url(fn () => $next_record ? OrderResource::getUrl('edit', ['record' => $next_record]) : NULL)
->visible(fn () => $next_record ?? FALSE),
Actions\DeleteAction::make(),
Actions\ForceDeleteAction::make(),
Actions\RestoreAction::make(),
];
}
protected function getActions(): array
{
$next_record = Order::select('id')->where('id', '>', $this->record->id)->orderBy('id')->first();
$previous_record = Order::select('id')->where('id', '<', $this->record->id)->orderBy('id','desc')->first();

return [
Actions\Action::make('previous')
->label('')
->icon('heroicon-s-chevron-left')
->color('secondary')
->url(fn () => $previous_record ? OrderResource::getUrl('edit', ['record' => $previous_record]) : NULL)
->visible(fn () => $previous_record ?? FALSE),
Actions\Action::make('next')
->label('')
->icon('heroicon-s-chevron-right')
->color('secondary')
->url(fn () => $next_record ? OrderResource::getUrl('edit', ['record' => $next_record]) : NULL)
->visible(fn () => $next_record ?? FALSE),
Actions\DeleteAction::make(),
Actions\ForceDeleteAction::make(),
Actions\RestoreAction::make(),
];
}
1 Reply
Dan Harrin
Dan Harrin2y ago
->iconButton() instead of ->label('')
Want results from more Discord servers?
Add your server