Содержит все Базовые методы.
Поле RelationRepeater
предназначено для работы с отношениями HasMany
и HasOne
.
Оно позволяет создавать, редактировать и удалять связанные записи прямо из формы основной модели.
Поле автоматически синхронизирует связанные записи при сохранении основной модели.
make(
string|Closure $label,
?string $relationName = null,
string|Closure|null $formatted = null,
ModelResource|string|null $resource = null,
)
make(
string|Closure $label,
?string $relationName = null,
string|Closure|null $formatted = null,
ModelResource|string|null $resource = null,
)
make(
string|Closure $label,
?string $relationName = null,
string|Closure|null $formatted = null,
ModelResource|string|null $resource = null,
)
make(
string|Closure $label,
?string $relationName = null,
string|Closure|null $formatted = null,
ModelResource|string|null $resource = null,
)
make(
string|Closure $label,
?string $relationName = null,
string|Closure|null $formatted = null,
ModelResource|string|null $resource = null,
)
$label
- заголовок поля,
$relationName
- имя отношения,
$formatted
- замыкание для форматирования значения поля в режиме "preview",
$resource
- ресурс связанной модели.
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
RelationRepeater::make(
'Comments',
'comments',
resource: CommentResource::class
)
namespaces
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
RelationRepeater::make(
'Comments',
'comments',
resource: CommentResource::class
)
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
RelationRepeater::make(
'Comments',
'comments',
resource: CommentResource::class
)
namespaces
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
RelationRepeater::make(
'Comments',
'comments',
resource: CommentResource::class
)
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
RelationRepeater::make(
'Comments',
'comments',
resource: CommentResource::class
)
По умолчанию поле использует все поля формы из указанного ресурса.
Однако вы можете переопределить набор полей с помощью метода fields()
.
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
use MoonShine\UI\Fields\ID;
use MoonShine\UI\Fields\Text;
RelationRepeater::make('Characteristics', 'characteristics')
->fields([
ID::make(),
Text::make('Name', 'name'),
Text::make('Value', 'value'),
])
namespaces
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
use MoonShine\UI\Fields\ID;
use MoonShine\UI\Fields\Text;
RelationRepeater::make('Characteristics', 'characteristics')
->fields([
ID::make(),
Text::make('Name', 'name'),
Text::make('Value', 'value'),
])
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
use MoonShine\UI\Fields\ID;
use MoonShine\UI\Fields\Text;
RelationRepeater::make('Characteristics', 'characteristics')
->fields([
ID::make(),
Text::make('Name', 'name'),
Text::make('Value', 'value'),
])
namespaces
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
use MoonShine\UI\Fields\ID;
use MoonShine\UI\Fields\Text;
RelationRepeater::make('Characteristics', 'characteristics')
->fields([
ID::make(),
Text::make('Name', 'name'),
Text::make('Value', 'value'),
])
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
use MoonShine\UI\Fields\ID;
use MoonShine\UI\Fields\Text;
RelationRepeater::make('Characteristics', 'characteristics')
->fields([
ID::make(),
Text::make('Name', 'name'),
Text::make('Value', 'value'),
])
Наличие поля ID
обязательно, иначе записи будут всегда добавляться.
Метод vertical()
изменяет отображение таблицы из горизонтального режима на вертикальный.
vertical(Closure|bool|null $condition = null)
vertical(Closure|bool|null $condition = null)
vertical(Closure|bool|null $condition = null)
vertical(Closure|bool|null $condition = null)
vertical(Closure|bool|null $condition = null)
RelationRepeater::make('Comments', 'comments')
->vertical()
RelationRepeater::make('Comments', 'comments')
->vertical()
RelationRepeater::make('Comments', 'comments')
->vertical()
RelationRepeater::make('Comments', 'comments')
->vertical()
RelationRepeater::make('Comments', 'comments')
->vertical()
Даёт возможность перетаскивать строки, тем самым изменяя сортировку.
->reorderable(url: '/endpoint')
->reorderable(url: '/endpoint')
->reorderable(url: '/endpoint')
->reorderable(url: '/endpoint')
->reorderable(url: '/endpoint')
По умолчанию поле позволяет добавлять новые элементы.
Это поведение можно изменить с помощью метода creatable()
.
creatable(
Closure|bool|null $condition = null,
?int $limit = null,
?ActionButtonContract $button = null
)
creatable(
Closure|bool|null $condition = null,
?int $limit = null,
?ActionButtonContract $button = null
)
creatable(
Closure|bool|null $condition = null,
?int $limit = null,
?ActionButtonContract $button = null
)
creatable(
Closure|bool|null $condition = null,
?int $limit = null,
?ActionButtonContract $button = null
)
creatable(
Closure|bool|null $condition = null,
?int $limit = null,
?ActionButtonContract $button = null
)
$condition
- условие, при котором метод должен быть применён,
$limit
- ограничение на количество возможных элементов,
$button
- возможность заменить кнопку добавления на свою.
Для возможности удаления элементов используется метод removable()
.
removable(
Closure|bool|null $condition = null,
array $attributes = []
)
removable(
Closure|bool|null $condition = null,
array $attributes = []
)
removable(
Closure|bool|null $condition = null,
array $attributes = []
)
removable(
Closure|bool|null $condition = null,
array $attributes = []
)
removable(
Closure|bool|null $condition = null,
array $attributes = []
)
RelationRepeater::make('Comments', 'comments')
->creatable(limit: 5)
->removable()
RelationRepeater::make('Comments', 'comments')
->creatable(limit: 5)
->removable()
RelationRepeater::make('Comments', 'comments')
->creatable(limit: 5)
->removable()
RelationRepeater::make('Comments', 'comments')
->creatable(limit: 5)
->removable()
RelationRepeater::make('Comments', 'comments')
->creatable(limit: 5)
->removable()
Метод buttons()
позволяет переопределить кнопки, используемые в поле.
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
use MoonShine\UI\Components\ActionButton;
RelationRepeater::make('Comments', 'comments')
->buttons([
ActionButton::make('', '#')
->icon('trash')
->onClick(fn() => 'remove()', 'prevent')
->class('btn-error')
->showInLine()
])
namespaces
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
use MoonShine\UI\Components\ActionButton;
RelationRepeater::make('Comments', 'comments')
->buttons([
ActionButton::make('', '#')
->icon('trash')
->onClick(fn() => 'remove()', 'prevent')
->class('btn-error')
->showInLine()
])
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
use MoonShine\UI\Components\ActionButton;
RelationRepeater::make('Comments', 'comments')
->buttons([
ActionButton::make('', '#')
->icon('trash')
->onClick(fn() => 'remove()', 'prevent')
->class('btn-error')
->showInLine()
])
namespaces
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
use MoonShine\UI\Components\ActionButton;
RelationRepeater::make('Comments', 'comments')
->buttons([
ActionButton::make('', '#')
->icon('trash')
->onClick(fn() => 'remove()', 'prevent')
->class('btn-error')
->showInLine()
])
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
use MoonShine\UI\Components\ActionButton;
RelationRepeater::make('Comments', 'comments')
->buttons([
ActionButton::make('', '#')
->icon('trash')
->onClick(fn() => 'remove()', 'prevent')
->class('btn-error')
->showInLine()
])
Модификатор таблицы
Метод modifyTable()
позволяет модифицировать таблицу (TableBuilder
).
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
use MoonShine\UI\Components\Table\TableBuilder;
RelationRepeater::make('Comments', 'comments')
->modifyTable(
fn(TableBuilder $table, bool $preview) => $table
->customAttributes([
'class' => 'custom-table'
])
)
namespaces
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
use MoonShine\UI\Components\Table\TableBuilder;
RelationRepeater::make('Comments', 'comments')
->modifyTable(
fn(TableBuilder $table, bool $preview) => $table
->customAttributes([
'class' => 'custom-table'
])
)
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
use MoonShine\UI\Components\Table\TableBuilder;
RelationRepeater::make('Comments', 'comments')
->modifyTable(
fn(TableBuilder $table, bool $preview) => $table
->customAttributes([
'class' => 'custom-table'
])
)
namespaces
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
use MoonShine\UI\Components\Table\TableBuilder;
RelationRepeater::make('Comments', 'comments')
->modifyTable(
fn(TableBuilder $table, bool $preview) => $table
->customAttributes([
'class' => 'custom-table'
])
)
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
use MoonShine\UI\Components\Table\TableBuilder;
RelationRepeater::make('Comments', 'comments')
->modifyTable(
fn(TableBuilder $table, bool $preview) => $table
->customAttributes([
'class' => 'custom-table'
])
)
Модификатор кнопки добавления
Метод modifyCreateButton()
позволяет изменить кнопку добавления.
modifyCreateButton(Closure $callback)
/**
* @param Closure(ActionButton $button, self $field): ActionButton $callback
*/
modifyCreateButton(Closure $callback)
/**
* @param Closure(ActionButton $button, self $field): ActionButton $callback
*/
modifyCreateButton(Closure $callback)
/**
* @param Closure(ActionButton $button, self $field): ActionButton $callback
*/
modifyCreateButton(Closure $callback)
/**
* @param Closure(ActionButton $button, self $field): ActionButton $callback
*/
modifyCreateButton(Closure $callback)
use MoonShine\UI\Components\ActionButton;
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
RelationRepeater::make('Comments', 'comments')
->modifyCreateButton(
fn(ActionButton $button) => $button->customAttributes([
'class' => 'btn-primary'
])
)
namespaces
use MoonShine\UI\Components\ActionButton;
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
RelationRepeater::make('Comments', 'comments')
->modifyCreateButton(
fn(ActionButton $button) => $button->customAttributes([
'class' => 'btn-primary'
])
)
use MoonShine\UI\Components\ActionButton;
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
RelationRepeater::make('Comments', 'comments')
->modifyCreateButton(
fn(ActionButton $button) => $button->customAttributes([
'class' => 'btn-primary'
])
)
namespaces
use MoonShine\UI\Components\ActionButton;
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
RelationRepeater::make('Comments', 'comments')
->modifyCreateButton(
fn(ActionButton $button) => $button->customAttributes([
'class' => 'btn-primary'
])
)
use MoonShine\UI\Components\ActionButton;
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
RelationRepeater::make('Comments', 'comments')
->modifyCreateButton(
fn(ActionButton $button) => $button->customAttributes([
'class' => 'btn-primary'
])
)
Модификатор кнопки удаления
Метод modifyRemoveButton()
позволяет изменить кнопку удаления.
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
use MoonShine\UI\Components\ActionButton;
RelationRepeater::make('Comments', 'comments')
->modifyRemoveButton(
fn(ActionButton $button) => $button
->customAttributes([
'class' => 'btn-secondary'
])
)
namespaces
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
use MoonShine\UI\Components\ActionButton;
RelationRepeater::make('Comments', 'comments')
->modifyRemoveButton(
fn(ActionButton $button) => $button
->customAttributes([
'class' => 'btn-secondary'
])
)
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
use MoonShine\UI\Components\ActionButton;
RelationRepeater::make('Comments', 'comments')
->modifyRemoveButton(
fn(ActionButton $button) => $button
->customAttributes([
'class' => 'btn-secondary'
])
)
namespaces
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
use MoonShine\UI\Components\ActionButton;
RelationRepeater::make('Comments', 'comments')
->modifyRemoveButton(
fn(ActionButton $button) => $button
->customAttributes([
'class' => 'btn-secondary'
])
)
use MoonShine\Laravel\Fields\Relationships\RelationRepeater;
use MoonShine\UI\Components\ActionButton;
RelationRepeater::make('Comments', 'comments')
->modifyRemoveButton(
fn(ActionButton $button) => $button
->customAttributes([
'class' => 'btn-secondary'
])
)