Кнопки на страницах ресурса отвечают за основные действия с элементами
и являются компонентами ActionButton.
В MoonShine есть множество методов, позволяющих переопределить у ресурса как отдельные
кнопки, так и всю группу.
Кнопки для создания, просмотра, редактирования, удаления и массового удаления размещены в отдельных классах,
чтобы применить к ним все необходимые методы и тем самым устранить дублирование, поскольку эти кнопки также используются в HasMany, BelongsToMany и т.д.
Методы topLeftButtons() и topRightButtons() в классе индексной страницы позволяют добавлять\переопределять
кнопки над таблицей.
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())
)
);
}
}

Метод modifyCreateButton() позволяет модифицировать кнопку создания нового элемента.
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();
}
Так же, вы можете переопределить кнопку.
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');
}

Метод modifyFiltersButton() позволяет модифицировать или переопределить кнопку фильтров.
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();
}

Для добавления\переопределения кнопок в индексной таблице, используйте метод buttons() в классе индексной страницы.
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()
)
);
}

Для массовых действий с элементами необходимо добавить метод 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()
);
}
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()
);
}

Метод modifyDetailButton() позволяет модифицировать или переопределить кнопку детального просмотра элемента.
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();
}

Метод modifyEditButton() позволяет модифицировать или переопределить кнопку редактирования элемента.
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');
}

Метод modifyDeleteButton() позволяет модифицировать или переопределить кнопку удаления элемента.
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');
}

Метод modifyMassDeleteButton() позволяет модифицировать или переопределить кнопку массового удаления.
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');
}

Чтобы добавить кнопки на страницу с формой, используйте метод buttons() в классе страницы формы.
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')
);
}

Метод formButtons() позволяет добавить\переопределить кнопки непосредственно в форму создания или редактирования.
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')
);
}

Чтобы добавить\переопределить кнопки на странице детального просмотра, используйте метод buttons() в классе детальной страницы.
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'));
}
