Litstack: Use a select field instead of oneRelation in nested repeatables
Using oneRelation or manyRelation in a form of nested repeatables causes a litstack error, which is not fixable at this moment. This is a workaround using a select field.
Repeatable
Create a repeatable containing the select field.
use App\Models\MyModel;...$form->select('my_model_id') ->title('MyModel') ->options( MyModel::all()->mapWithKeys(function ($item, $key) { return [$item->id => $item->title]; })->toArray() );
Retrieve Data in vue component
const getMyModel = async () => { try { const { data } = await axios.post('/api/my-model', { id: parseInt(repeatable.my_model_id), }); myModel.value = data; }};onMounted(() => { getMyModel();});
The api route points to the controller:
Route::post('/my-model', [MyModelController::class, 'getMyModel']);
public function getMyModel(Request $request): mixed{ if (! $request->id) { return response()->json([]); } $item = MyModel::where('id', $request->id)->firstOrFail(); return response()->json($item);}