Skip to content

Commit

Permalink
docs(resources): actions() method
Browse files Browse the repository at this point in the history
issue #425
  • Loading branch information
DissNik committed Apr 16, 2024
1 parent 6f9cf9e commit 92f0fa5
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 1 deletion.
56 changes: 56 additions & 0 deletions resources/views/pages/en/resources/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
['url' => '#modal', 'label' => 'Modal windows'],
['url' => '#redirects', 'label' => 'Redirects'],
['url' => '#active_actions', 'label' => 'Active actions'],
['url' => '#actions', 'label' => 'Buttons'],
['url' => '#components', 'label' => 'Components'],
['url' => '#boot', 'label' => 'Boot'],
]
Expand Down Expand Up @@ -271,6 +272,7 @@ public function redirectAfterDelete(): string
class PostResource extends ModelResource
{
//...

public function getActiveActions(): array // [tl! focus:start]
{
return ['create', 'view', 'update', 'delete', 'massDelete'];
Expand All @@ -280,6 +282,60 @@ public function getActiveActions(): array // [tl! focus:start]
}
</x-code>

<x-sub-title id="actions">Buttons</x-sub-title>

<x-p>
By default, the model resource index page only has a button to create.<br />
The <code>actions()</code> method allows you to add additional <x-link link="{{ to_page('action_button') }}">buttons</x-link>.
</x-p>

<x-code language="php">
namespace MoonShine\Resources;

class PostResource extends ModelResource
{
//...

public function actions(): array // [tl! focus:start]
{
return [
ActionButton::make('Refresh', '#')
->dispatchEvent(AlpineJs::event(JsEvent::TABLE_UPDATED, 'index-table'))
];
} // [tl! focus:end]

//...
}
</x-code>

<x-moonshine::divider label="Display" />

<x-p>
You can also change the display of the buttons,
display them in a line or in a drop-down menu to save space.
</x-p>

<x-code language="php">
namespace MoonShine\Resources;

class PostResource extends ModelResource
{
//...

public function actions(): array
{
return [
ActionButton::make('Button 1', '/')
->showInLine(), // [tl! focus]
ActionButton::make('Button 2', '/')
->showInDropdown() // [tl! focus]
];
} // [tl! focus:end]

//...
}
</x-code>

<x-sub-title id="components">Components</x-sub-title>

<x-p>
Expand Down
58 changes: 57 additions & 1 deletion resources/views/pages/ru/resources/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
['url' => '#modal', 'label' => 'Модальные окна'],
['url' => '#redirects', 'label' => 'Редиректы'],
['url' => '#active_actions', 'label' => 'Активные действия'],
['url' => '#actions', 'label' => 'Кнопки'],
['url' => '#components', 'label' => 'Компоненты'],
['url' => '#boot', 'label' => 'Boot'],
]
Expand Down Expand Up @@ -271,6 +272,7 @@ public function redirectAfterDelete(): string
class PostResource extends ModelResource
{
//...

public function getActiveActions(): array // [tl! focus:start]
{
return ['create', 'view', 'update', 'delete', 'massDelete'];
Expand All @@ -280,7 +282,61 @@ public function getActiveActions(): array // [tl! focus:start]
}
</x-code>

<x-sub-title id="components">Components</x-sub-title>
<x-sub-title id="actions">Кнопки</x-sub-title>

<x-p>
По умолчанию на индексной странице ресурса модели присутствует только кнопка для создания.<br />
Метод <code>actions()</code> позволяет добавить дополнительные <x-link link="{{ to_page('action_button') }}">кнопки</x-link>.
</x-p>

<x-code language="php">
namespace MoonShine\Resources;

class PostResource extends ModelResource
{
//...

public function actions(): array // [tl! focus:start]
{
return [
ActionButton::make('Refresh', '#')
->dispatchEvent(AlpineJs::event(JsEvent::TABLE_UPDATED, 'index-table'))
];
} // [tl! focus:end]

//...
}
</x-code>

<x-moonshine::divider label="Отображение" />

<x-p>
Вы также можете изменить отображение кнопок,
отображать их в линию или же в выпадающем меню для экономии места.
</x-p>

<x-code language="php">
namespace MoonShine\Resources;

class PostResource extends ModelResource
{
//...

public function actions(): array
{
return [
ActionButton::make('Button 1', '/')
->showInLine(), // [tl! focus]
ActionButton::make('Button 2', '/')
->showInDropdown() // [tl! focus]
];
} // [tl! focus:end]

//...
}
</x-code>

<x-sub-title id="components">Компоненты</x-sub-title>

<x-p>
Лучший способ изменять компоненты страниц это опубликовать страницы
Expand Down

0 comments on commit 92f0fa5

Please sign in to comment.