Buttons on resource pages are responsible for the main actions with elements
and are components of ActionButton.
There are many methods in MoonShine that allow you to override a resource as separate
buttons and the entire group.
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.
The topLeftButtons() and topRightButtons() methods in the index page class allow you to add\override
buttons above the table.
namespace App\MoonShine\Resources\Post\Pages;
use MoonShine\Support\AlpineJs;
use MoonShine\Support\Enums\JsEvent;
use MoonShine\Support\ListOf;
use MoonShine\UI\Components\ActionButton;
use MoonShine\Laravel\Pages\Crud\IndexPage;
class PostIndexPage extends IndexPage
{
protected function topLeftButtons(): ListOf
{
return parent::topLeftButtons()
->add(
ActionButton::make('Refresh', '#')
->dispatchEvent(
AlpineJs::event(JsEvent::TABLE_UPDATED, $this->getListComponentName())
)
);
}
}
namespaces
namespace App\MoonShine\Resources\Post\Pages;
use MoonShine\Support\AlpineJs;
use MoonShine\Support\Enums\JsEvent;
use MoonShine\Support\ListOf;
use MoonShine\UI\Components\ActionButton;
use MoonShine\Laravel\Pages\Crud\IndexPage;
class PostIndexPage extends IndexPage
{
// ...
protected function topLeftButtons(): ListOf
{
return parent::topLeftButtons()
->add(
ActionButton::make('Refresh', '#')
->dispatchEvent(
AlpineJs::event(JsEvent::TABLE_UPDATED, $this->getListComponentName())
)
);
}
}
namespace App\MoonShine\Resources\Post\Pages;
use MoonShine\Support\AlpineJs;
use MoonShine\Support\Enums\JsEvent;
use MoonShine\Support\ListOf;
use MoonShine\UI\Components\ActionButton;
use MoonShine\Laravel\Pages\Crud\IndexPage;
class PostIndexPage extends IndexPage
{
// ...
protected function topLeftButtons(): ListOf
{
return parent::topLeftButtons()
->add(
ActionButton::make('Refresh', '#')
->dispatchEvent(
AlpineJs::event(JsEvent::TABLE_UPDATED, $this->getListComponentName())
)
);
}
}
namespaces
namespace App\MoonShine\Resources\Post\Pages;
use MoonShine\Support\AlpineJs;
use MoonShine\Support\Enums\JsEvent;
use MoonShine\Support\ListOf;
use MoonShine\UI\Components\ActionButton;
use MoonShine\Laravel\Pages\Crud\IndexPage;
class PostIndexPage extends IndexPage
{
// ...
protected function topLeftButtons(): ListOf
{
return parent::topLeftButtons()
->add(
ActionButton::make('Refresh', '#')
->dispatchEvent(
AlpineJs::event(JsEvent::TABLE_UPDATED, $this->getListComponentName())
)
);
}
}
namespace App\MoonShine\Resources\Post\Pages;
use MoonShine\Support\AlpineJs;
use MoonShine\Support\Enums\JsEvent;
use MoonShine\Support\ListOf;
use MoonShine\UI\Components\ActionButton;
use MoonShine\Laravel\Pages\Crud\IndexPage;
class PostIndexPage extends IndexPage
{
// ...
protected function topLeftButtons(): ListOf
{
return parent::topLeftButtons()
->add(
ActionButton::make('Refresh', '#')
->dispatchEvent(
AlpineJs::event(JsEvent::TABLE_UPDATED, $this->getListComponentName())
)
);
}
}

The modifyCreateButton() method allows you to modify the button for creating a new element.
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyCreateButton(ActionButtonContract $button): ActionButtonContract
{
return $button->error();
}
namespaces
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyCreateButton(ActionButtonContract $button): ActionButtonContract
{
return $button->error();
}
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyCreateButton(ActionButtonContract $button): ActionButtonContract
{
return $button->error();
}
namespaces
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyCreateButton(ActionButtonContract $button): ActionButtonContract
{
return $button->error();
}
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyCreateButton(ActionButtonContract $button): ActionButtonContract
{
return $button->error();
}
Also, you can redefine the button.
use MoonShine\Contracts\UI\ActionButtonContract;
use MoonShine\UI\Components\ActionButton;
protected function modifyCreateButton(ActionButtonContract $button): ActionButtonContract
{
return ActionButton::make('Create');
}
namespaces
use MoonShine\Contracts\UI\ActionButtonContract;
use MoonShine\UI\Components\ActionButton;
protected function modifyCreateButton(ActionButtonContract $button): ActionButtonContract
{
return ActionButton::make('Create');
}
use MoonShine\Contracts\UI\ActionButtonContract;
use MoonShine\UI\Components\ActionButton;
protected function modifyCreateButton(ActionButtonContract $button): ActionButtonContract
{
return ActionButton::make('Create');
}
namespaces
use MoonShine\Contracts\UI\ActionButtonContract;
use MoonShine\UI\Components\ActionButton;
protected function modifyCreateButton(ActionButtonContract $button): ActionButtonContract
{
return ActionButton::make('Create');
}
use MoonShine\Contracts\UI\ActionButtonContract;
use MoonShine\UI\Components\ActionButton;
protected function modifyCreateButton(ActionButtonContract $button): ActionButtonContract
{
return ActionButton::make('Create');
}

The modifyFiltersButton() method allows you to modify or override the filter button.
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyFiltersButton(ActionButtonContract $button): ActionButtonContract
{
return $button->error();
}
namespaces
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyFiltersButton(ActionButtonContract $button): ActionButtonContract
{
return $button->error();
}
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyFiltersButton(ActionButtonContract $button): ActionButtonContract
{
return $button->error();
}
namespaces
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyFiltersButton(ActionButtonContract $button): ActionButtonContract
{
return $button->error();
}
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyFiltersButton(ActionButtonContract $button): ActionButtonContract
{
return $button->error();
}

To add/override buttons in the index table, use the buttons() method in the index page class.
use Illuminate\Database\Eloquent\Model;
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function buttons(): ListOf
{
return parent::buttons()
->prepend(
ActionButton::make(
'Link'
fn(Model $item) => '/endpoint?id=' . $item->getKey()
)
);
}
namespaces
use Illuminate\Database\Eloquent\Model;
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function buttons(): ListOf
{
return parent::buttons()
->prepend(
ActionButton::make(
'Link'
fn(Model $item) => '/endpoint?id=' . $item->getKey()
)
);
}
use Illuminate\Database\Eloquent\Model;
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function buttons(): ListOf
{
return parent::buttons()
->prepend(
ActionButton::make(
'Link'
fn(Model $item) => '/endpoint?id=' . $item->getKey()
)
);
}
namespaces
use Illuminate\Database\Eloquent\Model;
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function buttons(): ListOf
{
return parent::buttons()
->prepend(
ActionButton::make(
'Link'
fn(Model $item) => '/endpoint?id=' . $item->getKey()
)
);
}
use Illuminate\Database\Eloquent\Model;
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function buttons(): ListOf
{
return parent::buttons()
->prepend(
ActionButton::make(
'Link'
fn(Model $item) => '/endpoint?id=' . $item->getKey()
)
);
}

For mass actions with elements, you need to add the bulk() method.
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function buttons(): ListOf
{
return parent::buttons()
->prepend(
ActionButton::make('Link', '/endpoint')
->bulk()
);
}
namespaces
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function buttons(): ListOf
{
return parent::buttons()
->prepend(
ActionButton::make('Link', '/endpoint')
->bulk()
);
}
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function buttons(): ListOf
{
return parent::buttons()
->prepend(
ActionButton::make('Link', '/endpoint')
->bulk()
);
}
namespaces
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function buttons(): ListOf
{
return parent::buttons()
->prepend(
ActionButton::make('Link', '/endpoint')
->bulk()
);
}
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function buttons(): ListOf
{
return parent::buttons()
->prepend(
ActionButton::make('Link', '/endpoint')
->bulk()
);
}

The modifyDetailButton() method allows you to modify or override the detail view button of an element.
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyDetailButton(ActionButtonContract $button): ActionButtonContract
{
return $button->warning();
}
namespaces
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyDetailButton(ActionButtonContract $button): ActionButtonContract
{
return $button->warning();
}
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyDetailButton(ActionButtonContract $button): ActionButtonContract
{
return $button->warning();
}
namespaces
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyDetailButton(ActionButtonContract $button): ActionButtonContract
{
return $button->warning();
}
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyDetailButton(ActionButtonContract $button): ActionButtonContract
{
return $button->warning();
}

The modifyEditButton() method allows you to modify or override an element's edit button.
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyEditButton(ActionButtonContract $button): ActionButtonContract
{
return $button->icon('pencil-square');
}
namespaces
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyEditButton(ActionButtonContract $button): ActionButtonContract
{
return $button->icon('pencil-square');
}
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyEditButton(ActionButtonContract $button): ActionButtonContract
{
return $button->icon('pencil-square');
}
namespaces
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyEditButton(ActionButtonContract $button): ActionButtonContract
{
return $button->icon('pencil-square');
}
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyEditButton(ActionButtonContract $button): ActionButtonContract
{
return $button->icon('pencil-square');
}

The modifyDeleteButton() method allows you to modify or override an element's delete button.
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyDeleteButton(ActionButtonContract $button): ActionButtonContract
{
return $button->icon('x-mark');
}
namespaces
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyDeleteButton(ActionButtonContract $button): ActionButtonContract
{
return $button->icon('x-mark');
}
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyDeleteButton(ActionButtonContract $button): ActionButtonContract
{
return $button->icon('x-mark');
}
namespaces
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyDeleteButton(ActionButtonContract $button): ActionButtonContract
{
return $button->icon('x-mark');
}
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyDeleteButton(ActionButtonContract $button): ActionButtonContract
{
return $button->icon('x-mark');
}

The modifyMassDeleteButton() method allows you to modify or override the mass delete button.
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyMassDeleteButton(ActionButtonContract $button): ActionButtonContract
{
return $button->icon('x-mark');
}
namespaces
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyMassDeleteButton(ActionButtonContract $button): ActionButtonContract
{
return $button->icon('x-mark');
}
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyMassDeleteButton(ActionButtonContract $button): ActionButtonContract
{
return $button->icon('x-mark');
}
namespaces
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyMassDeleteButton(ActionButtonContract $button): ActionButtonContract
{
return $button->icon('x-mark');
}
use MoonShine\Contracts\UI\ActionButtonContract;
protected function modifyMassDeleteButton(ActionButtonContract $button): ActionButtonContract
{
return $button->icon('x-mark');
}

To add buttons to a form page, use the buttons() method in the form page class.
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function buttons(): ListOf
{
return parent::buttons()
->add(
ActionButton::make('Link')->method('updateSomething')
);
}
namespaces
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function buttons(): ListOf
{
return parent::buttons()
->add(
ActionButton::make('Link')->method('updateSomething')
);
}
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function buttons(): ListOf
{
return parent::buttons()
->add(
ActionButton::make('Link')->method('updateSomething')
);
}
namespaces
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function buttons(): ListOf
{
return parent::buttons()
->add(
ActionButton::make('Link')->method('updateSomething')
);
}
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function buttons(): ListOf
{
return parent::buttons()
->add(
ActionButton::make('Link')->method('updateSomething')
);
}

The formButtons() method allows you to add\override buttons directly to the create or edit form.
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function formButtons(): ListOf
{
return parent::formButtons()
->add(
ActionButton::make('Back', fn() => $this->getIndexPageUrl())->class('btn-lg')
);
}
namespaces
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function formButtons(): ListOf
{
return parent::formButtons()
->add(
ActionButton::make('Back', fn() => $this->getIndexPageUrl())->class('btn-lg')
);
}
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function formButtons(): ListOf
{
return parent::formButtons()
->add(
ActionButton::make('Back', fn() => $this->getIndexPageUrl())->class('btn-lg')
);
}
namespaces
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function formButtons(): ListOf
{
return parent::formButtons()
->add(
ActionButton::make('Back', fn() => $this->getIndexPageUrl())->class('btn-lg')
);
}
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function formButtons(): ListOf
{
return parent::formButtons()
->add(
ActionButton::make('Back', fn() => $this->getIndexPageUrl())->class('btn-lg')
);
}

To add\override buttons on the detail page, use the buttons() method in the detail page class.
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function buttons(): ListOf
{
return parent::buttons()
->add(ActionButton::make('Link', '/endpoint'));
}
namespaces
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function buttons(): ListOf
{
return parent::buttons()
->add(ActionButton::make('Link', '/endpoint'));
}
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function buttons(): ListOf
{
return parent::buttons()
->add(ActionButton::make('Link', '/endpoint'));
}
namespaces
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function buttons(): ListOf
{
return parent::buttons()
->add(ActionButton::make('Link', '/endpoint'));
}
use MoonShine\UI\Components\ActionButton;
use MoonShine\Support\ListOf;
protected function buttons(): ListOf
{
return parent::buttons()
->add(ActionButton::make('Link', '/endpoint'));
}
