Reuse Component Function

Hello - is there a way to reuse a function on a form component? For example, I have a Select element and I only want it to be required if it is visible
Select::make('name')
->required(function ($get) {
$id = $get('category_id');
$category = Category::find($id);
return !$category->page_one;
})
->visible(function ($get) {
$id = $get('category_id');
$category = Category::find($id);
return !$category->page_one;
})
Select::make('name')
->required(function ($get) {
$id = $get('category_id');
$category = Category::find($id);
return !$category->page_one;
})
->visible(function ($get) {
$id = $get('category_id');
$category = Category::find($id);
return !$category->page_one;
})
I have to write two separate checks - one for visible and one for required. But they are the same thing. It feels inefficient. Is there a better way to do this? Thank you
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server