Unique and RelationManagers

I have a relation manager for my RecipeResource. The Relationamanager has itself a form, with a Datepicker field:
public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make("name"),
DatePicker::make("published_at")
->unique(callback: function(Unique $rule) {
return $rule
->where("recipe_id", "XXX");
})
->default(now())
->required()
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make("name"),
DatePicker::make("published_at")
->unique(callback: function(Unique $rule) {
return $rule
->where("recipe_id", "XXX");
})
->default(now())
->required()
]);
}
The date should be unique within the Recipe. How do I get the recipe_id inside the unique callback (the XXXin the code)? As far as I understand is $rule the only param for the callback.
2 Replies
Dan Harrin
Dan Harrin16mo ago
$livewire->ownerRecord->id
bernhard
bernhard16mo ago
Thanks. That solved it!