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 ActionButton.
In the MoonShine admin panel there are many methods that allow you to override the resource as a separate button , and the whole group .
More detailed information about the ActionButton component.
The buttons for creating, viewing, editing, deleting and mass deleting are placed in separate classes, in order to apply all the necessary methods to them and thereby eliminate duplication, since these buttons are also used in HasMany, BelongsToMany, etc.
use MoonShine\ActionButtons\ActionButton;
protected function modifyDetailButton(ActionButton $button): ActionButton
{
return $button->warning();
}
Override
The getDetailButton() method allows you to override the element's detail view button.
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Buttons\DetailButton;
public function getDetailButton(bool $isAsync = false): ActionButton
{
return DetailButton::for(
$this,
isAsync: $isAsync
);
}
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Buttons\DetailButton;
public function getDetailButton(bool $isAsync = false): ActionButton
{
return DetailButton::for(
$this,
isAsync: $isAsync
);
}
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Buttons\DetailButton;
public function getDetailButton(bool $isAsync = false): ActionButton
{
return DetailButton::for(
$this,
isAsync: $isAsync
);
}
use MoonShine\ActionButtons\ActionButton;
protected function modifyExportButton(ActionButton $button): ActionButton
{
return $button->secondary();
}
Override
The getExportButton() method allows you to override the export button.
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Buttons\ExportButton;
public function getExportButton(): ActionButton
{
return ExportButton::for($this, export: $this->export());
}
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Buttons\ExportButton;
public function getExportButton(): ActionButton
{
return ExportButton::for($this, export: $this->export());
}
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Buttons\ExportButton;
public function getExportButton(): ActionButton
{
return ExportButton::for($this, export: $this->export());
}
use MoonShine\ActionButtons\ActionButton;
protected function modifyImportButton(ActionButton $button): ActionButton
{
return $button->error();
}
Override
The getImportButton() method allows you to override the import button.
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Buttons\ImportButton;
public function getImportButton(): ActionButton
{
return ImportButton::for($this, import: $this->import());
}
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Buttons\ImportButton;
public function getImportButton(): ActionButton
{
return ImportButton::for($this, import: $this->import());
}
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Buttons\ImportButton;
public function getImportButton(): ActionButton
{
return ImportButton::for($this, import: $this->import());
}
use MoonShine\ActionButtons\ActionButton;
protected function modifyFiltersButton(ActionButton $button): ActionButton
{
return $button->error();
}
Override
The getFiltersButton() method allows you to override the filters button.
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Buttons\FiltersButton;
public function getFiltersButton(): ActionButton
{
return FiltersButton::for($this);
}
useMoonShine\ActionButtons\ActionButton;
useMoonShine\Buttons\FiltersButton;
publicfunctiongetFiltersButton():ActionButton
{
returnFiltersButton::for($this);
}
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Buttons\FiltersButton;
public function getFiltersButton(): ActionButton
{
return FiltersButton::for($this);
}
useMoonShine\ActionButtons\ActionButton;
useMoonShine\Buttons\FiltersButton;
publicfunctiongetFiltersButton():ActionButton
{
returnFiltersButton::for($this);
}
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Buttons\FiltersButton;
public function getFiltersButton(): ActionButton
{
return FiltersButton::for($this);
}
By default, the model resource index page only has a button to create.
The actions() method allows you to add additional buttons .
namespace MoonShine\Resources;
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Enums\JsEvent;
use MoonShine\Resources\ModelResource;
use MoonShine\Support\AlpineJs;
class PostResource extends ModelResource
{
public function actions(): array
{
return [
ActionButton::make('Refresh', '#')
->dispatchEvent(AlpineJs::event(JsEvent::TABLE_UPDATED, 'index-table'))
];
}
}
namespace MoonShine\Resources;
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Enums\JsEvent;
use MoonShine\Resources\ModelResource;
use MoonShine\Support\AlpineJs;
class PostResource extends ModelResource
{
//...
public function actions(): array
{
return [
ActionButton::make('Refresh', '#')
->dispatchEvent(AlpineJs::event(JsEvent::TABLE_UPDATED, 'index-table'))
];
}
//...
}
namespace MoonShine\Resources;
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Enums\JsEvent;
use MoonShine\Resources\ModelResource;
use MoonShine\Support\AlpineJs;
class PostResource extends ModelResource
{
//...
public function actions(): array
{
return [
ActionButton::make('Refresh', '#')
->dispatchEvent(AlpineJs::event(JsEvent::TABLE_UPDATED, 'index-table'))
];
}
//...
}
The buttons() method allows you to specify additional buttons, which will be displayed in the index table, in the creation and editing forms, as well as on the detailed page, if they are not overridden for pages by the corresponding methods indexButton() , formButtons() and detailButtons() .
namespace MoonShine\Resources;
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Resources\ModelResource;
class PostResource extends ModelResource
{
public function buttons(): array
{
return [
ActionButton::make('Link', '/endpoint')
];
}
}
namespaceMoonShine\Resources;
useMoonShine\ActionButtons\ActionButton;
useMoonShine\Resources\ModelResource;
classPostResourceextendsModelResource
{
//...
publicfunctionbuttons():array
{
return [
ActionButton::make('Link', '/endpoint')
];
}
//...
}
namespace MoonShine\Resources;
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Resources\ModelResource;
class PostResource extends ModelResource
{
//...
public function buttons(): array
{
return [
ActionButton::make('Link', '/endpoint')
];
}
//...
}
namespaceMoonShine\Resources;
useMoonShine\ActionButtons\ActionButton;
useMoonShine\Resources\ModelResource;
classPostResourceextendsModelResource
{
//...
publicfunctionbuttons():array
{
return [
ActionButton::make('Link', '/endpoint')
];
}
//...
}
namespace MoonShine\Resources;
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Resources\ModelResource;
class PostResource extends ModelResource
{
//...
public function buttons(): array
{
return [
ActionButton::make('Link', '/endpoint')
];
}
//...
}
To add buttons to a page with a form, use the formButtons() method.
namespace MoonShine\Resources;
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Resources\ModelResource;
class PostResource extends ModelResource
{
public function formButtons(): array
{
return [
ActionButton::make('Link')->method('updateSomething')
];
}
}
namespace MoonShine\Resources;
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Resources\ModelResource;
class PostResource extends ModelResource
{
//...
public function formButtons(): array
{
return [
ActionButton::make('Link')->method('updateSomething')
];
}
//...
}
namespace MoonShine\Resources;
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Resources\ModelResource;
class PostResource extends ModelResource
{
//...
public function formButtons(): array
{
return [
ActionButton::make('Link')->method('updateSomething')
];
}
//...
}
Group override
If you want to completely change all the buttons on an element on a form page, then you need to override the getFormItemButtons() method in the resource.
namespace MoonShine\Resources;
use MoonShine\Resources\ModelResource;
class PostResource extends ModelResource
{
public function getFormItemButtons(): array
{
return [
...$this->getFormButtons(),
$this->getDetailButton(),
$this->getDeleteButton(
redirectAfterDelete: $this->redirectAfterDelete(),
isAsync: false
),
];
}
}
To add buttons on a detail page, use the detailButtons() method.
namespace MoonShine\Resources;
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Resources\ModelResource;
class PostResource extends ModelResource
{
public function detailButtons(): array
{
return [
ActionButton::make('Link', '/endpoint')
];
}
}
namespaceMoonShine\Resources;
useMoonShine\ActionButtons\ActionButton;
useMoonShine\Resources\ModelResource;
classPostResourceextendsModelResource
{
//...
publicfunctiondetailButtons():array
{
return [
ActionButton::make('Link', '/endpoint')
];
}
//...
}
namespace MoonShine\Resources;
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Resources\ModelResource;
class PostResource extends ModelResource
{
//...
public function detailButtons(): array
{
return [
ActionButton::make('Link', '/endpoint')
];
}
//...
}
namespaceMoonShine\Resources;
useMoonShine\ActionButtons\ActionButton;
useMoonShine\Resources\ModelResource;
classPostResourceextendsModelResource
{
//...
publicfunctiondetailButtons():array
{
return [
ActionButton::make('Link', '/endpoint')
];
}
//...
}
namespace MoonShine\Resources;
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Resources\ModelResource;
class PostResource extends ModelResource
{
//...
public function detailButtons(): array
{
return [
ActionButton::make('Link', '/endpoint')
];
}
//...
}
Group override
If you want to completely change all the element buttons on the detail page, then you need to override the getDetailItemButtons() method in the resource.
namespace MoonShine\Resources;
use MoonShine\Resources\ModelResource;
class PostResource extends ModelResource
{
public function getDetailItemButtons(): array
{
return [
...$this->getDetailButtons(),
$this->getEditButton(
isAsync: $this->isAsync(),
),
$this->getDeleteButton(
redirectAfterDelete: $this->redirectAfterDelete(),
isAsync: false
),
];
}
}