Issue With Searchable Select

Hey All - I have a dynamically created schema as shown below:
->schema(function ($record) {
$class = new EditEvent;
$orderSchema = [];
foreach ($record->orders as $order) {
$orderSchema[] = $class->getEditForm($order)[0];
}

return $orderSchema;
})
->schema(function ($record) {
$class = new EditEvent;
$orderSchema = [];
foreach ($record->orders as $order) {
$orderSchema[] = $class->getEditForm($order)[0];
}

return $orderSchema;
})
Each event can have multiple orders, and each order has many selections. So instead of using a relation manager to make selections, I am dynamically generate this schema using the ->getEditForm() function and displaying it directly on the EditEvent form. I'm running into an issue with using searchable(). When I use searchable, all of the menu options are shown based on the first order. But when searchable() is not used, the menu options are displayed correctly based on the order that is passed to the function.
// this works correctly displaying the meals based on the order
Select::make('meal')
->label('Menu Option')
// ->searchable()
->options(function() use ($order) {
Log::debug($order->id);
$meals = Meal::where([
['kitchen_id', $order->provider_id],
['approved', true],
])->get();
$returnArray = [];
foreach($meals as $meal) {
$returnArray[$meal->id] = $meal->name . ' - $' . number_format($meal->price, 2, '.', ',');
}
return $returnArray;
})

// this does not work correctly
// it always uses the first order to pull the meals
Select::make('meal')
->label('Menu Option')
->searchable()
->options(function() use ($order) {
Log::debug($order->id);
$meals = Meal::where([
['kitchen_id', $order->provider_id],
['approved', true],
])->get();
$returnArray = [];
foreach($meals as $meal) {
$returnArray[$meal->id] = $meal->name . ' - $' . number_format($meal->price, 2, '.', ',');
}
return $returnArray;
})
// this works correctly displaying the meals based on the order
Select::make('meal')
->label('Menu Option')
// ->searchable()
->options(function() use ($order) {
Log::debug($order->id);
$meals = Meal::where([
['kitchen_id', $order->provider_id],
['approved', true],
])->get();
$returnArray = [];
foreach($meals as $meal) {
$returnArray[$meal->id] = $meal->name . ' - $' . number_format($meal->price, 2, '.', ',');
}
return $returnArray;
})

// this does not work correctly
// it always uses the first order to pull the meals
Select::make('meal')
->label('Menu Option')
->searchable()
->options(function() use ($order) {
Log::debug($order->id);
$meals = Meal::where([
['kitchen_id', $order->provider_id],
['approved', true],
])->get();
$returnArray = [];
foreach($meals as $meal) {
$returnArray[$meal->id] = $meal->name . ' - $' . number_format($meal->price, 2, '.', ',');
}
return $returnArray;
})
Does anyone have any ideas about what might be going on here? Thank you!
0 Replies
No replies yetBe the first to reply to this messageJoin