Repeater::make('Links')
->relationship('weblinks')
->schema([
TextInput::make('url')
->url()
->disabled(fn (Get $get) => !Weblink::typeEditable($get('type'))) //readonly on some types
->dehydrated(),
Select::make('type')
->options(Weblink::getSelectWeblinkType())
->disabled(fn (Get $get) => !Weblink::typeEditable($get('type')))
->dehydrated()
])
->addActionLabel('New Link')
->defaultItems(0)
->deleteAction(function (Action $action) {
return $action->before(function ($state, $arguments, $action) {
if (isset($state[$arguments["item"]])) {
$item_id = Arr::get($arguments, "item");
$item = Arr::get($state, $item_id);
$type = Arr::get($item, "type");
if (Weblink::typeEditable($type)) {
return $action->hidden(false);
} else {
Notification::make()
->title('Error')
->body("Type not allowed")
->status('danger')
->send();
return $action->cancel();
}
}
});
})
Repeater::make('Links')
->relationship('weblinks')
->schema([
TextInput::make('url')
->url()
->disabled(fn (Get $get) => !Weblink::typeEditable($get('type'))) //readonly on some types
->dehydrated(),
Select::make('type')
->options(Weblink::getSelectWeblinkType())
->disabled(fn (Get $get) => !Weblink::typeEditable($get('type')))
->dehydrated()
])
->addActionLabel('New Link')
->defaultItems(0)
->deleteAction(function (Action $action) {
return $action->before(function ($state, $arguments, $action) {
if (isset($state[$arguments["item"]])) {
$item_id = Arr::get($arguments, "item");
$item = Arr::get($state, $item_id);
$type = Arr::get($item, "type");
if (Weblink::typeEditable($type)) {
return $action->hidden(false);
} else {
Notification::make()
->title('Error')
->body("Type not allowed")
->status('danger')
->send();
return $action->cancel();
}
}
});
})