- Basics
- Create button
- Detail button
- Edit button
- Delete button
- Mass delete button
- Filters button
- Top buttons on index page
- Index table buttons
- Form buttons
- Detail page buttons
Basics
Buttons are displayed on resource pages: index page, form pages (create / edit), and detail page.
They are responsible for basic actions with elements and are components of ActionButton.
In the MoonShine admin panel, there are many methods that allow you to override either a single button for the resource or an entire group.
More detailed information about the ActionButton component.
The buttons for creating, viewing, editing, deleting, and mass deleting are placed in separate classes to apply all necessary methods to them and thereby eliminate duplication, as these buttons are also used in HasMany, BelongsToMany, etc.
Create button
The modifyCreateButton()
method allows you to modify the button for creating a new item.
protected function modifyCreateButton(ActionButtonContract $button): ActionButtonContract{ return $button->error();}
You can also override the button through this method
protected function modifyCreateButton(ActionButtonContract $button): ActionButtonContract{ return ActionButton::make('Create');}
Detail button
The modifyDetailButton()
method allows you to modify or override the button for viewing the details of an item.
protected function modifyDetailButton(ActionButtonContract $button): ActionButtonContract{ return $button->warning();}
Edit button
The modifyEditButton()
method allows you to modify or override the button for editing an item.
protected function modifyEditButton(ActionButtonContract $button): ActionButtonContract{ return $button->icon('pencil-square');}
Delete button
The modifyDeleteButton()
method allows you to modify or override the button for deleting an item.
protected function modifyDeleteButton(ActionButtonContract $button): ActionButtonContract{ return $button->icon('x-mark');}
Mass delete button
The modifyMassDeleteButton()
method allows you to modify or override the button for mass deleting.
protected function modifyMassDeleteButton(ActionButtonContract $button): ActionButtonContract{ return $button->icon('x-mark');}
Filters button
Modification
The modifyFiltersButton()
method allows you to overwrite or modify the filters button.
protected function modifyFiltersButton(ActionButtonContract $button): ActionButtonContract{ return $button->error();}
Top buttons on index page
By default, the model resource index page has only a create button.
The topButtons()
method allows you to add additional buttons.
class PostResource extends ModelResource{ //... protected function topButtons(): ListOf { return parent::topButtons()->add( ActionButton::make('Refresh', '#') ->dispatchEvent(AlpineJs::event(JsEvent::TABLE_UPDATED, $this->getListComponentName())) ); } //...}
Index table buttons
To add buttons in the index table, use the indexButtons()
method.
class PostResource extends ModelResource{ //... protected function indexButtons(): ListOf { return parent::indexButtons()->prepend( ActionButton::make( 'Link', fn(Model $item) => '/endpoint?id=' . $item->getKey() ) ); } //...}
For bulk actions with elements, you need to add the bulk()
method.
protected function indexButtons(): ListOf{ return parent::indexButtons()->prepend( ActionButton::make('Link', '/endpoint') ->bulk() );}
Form buttons
To add buttons to the form page, use the formButtons()
method.
class PostResource extends ModelResource{ //... protected function formButtons(): ListOf { return parent::formButtons()->add(ActionButton::make('Link')->method('updateSomething')); } //...}
The formBuilderButtons()
method allows you to add additional buttons in the create or edit form.
class PostResource extends ModelResource{ //... protected function formBuilderButtons(): ListOf { return parent::formBuilderButtons()->add( ActionButton::make('Back', fn() => $this->getIndexPageUrl())->class('btn-lg') ); } //...}
Detail page buttons
To add buttons to the detail view page, use the detailButtons()
method.
class PostResource extends ModelResource{ //... protected function detailButtons(): ListOf { return parent::detailButtons()->add(ActionButton::make('Link', '/endpoint')); } //...}