class ProductResource extends Resource {
...
Select::make('category_id')...,
Select::make('sub_category_id')...,
Repeater::make('locations')
->schema([
Select::make('warehouse_id'),
Select::make('location_id'),
])...,
}
class EditProduct extends EditRecord {
protected function fillForm(): void {
$data = $this->getRecord()->attributesToArray();
// WORKS:
$product = $this->getRecord();
$subCategory = $product->subCategory;
$data['sub_category_id'] = $product->sub_category_id;
$data['category_id'] = $subCategory->category_id;
// DOESN'T WORK, I’ve been trying to edit the repeater data, but I can’t. Only the location data from the database is loaded (So, for now, only an ID is loaded in the locations, and the warehouse is left unselected), and it doesn’t consider my changes:
$data['locations'] = [
[
'warehouse_id' => 1, // Random data for testing
'location_id' => 10,
],
[
'warehouse_id' => 2,
'location_id' => 20,
],
];
$this->fillFormWithDataAndCallHooks($product, $data);
}
}
class ProductResource extends Resource {
...
Select::make('category_id')...,
Select::make('sub_category_id')...,
Repeater::make('locations')
->schema([
Select::make('warehouse_id'),
Select::make('location_id'),
])...,
}
class EditProduct extends EditRecord {
protected function fillForm(): void {
$data = $this->getRecord()->attributesToArray();
// WORKS:
$product = $this->getRecord();
$subCategory = $product->subCategory;
$data['sub_category_id'] = $product->sub_category_id;
$data['category_id'] = $subCategory->category_id;
// DOESN'T WORK, I’ve been trying to edit the repeater data, but I can’t. Only the location data from the database is loaded (So, for now, only an ID is loaded in the locations, and the warehouse is left unselected), and it doesn’t consider my changes:
$data['locations'] = [
[
'warehouse_id' => 1, // Random data for testing
'location_id' => 10,
],
[
'warehouse_id' => 2,
'location_id' => 20,
],
];
$this->fillFormWithDataAndCallHooks($product, $data);
}
}