demonshide
demonshide
FFilament
Created by demonshide on 2/3/2025 in #❓┊help
How to Edit the Data of a Repeater
How do I modify the data of a repeater? In my model, a category has subcategories, and a warehouse has locations. For the form, I managed to load the subcategories based on the selected category and to load the locations after selecting the warehouse. Then, a product has a subcategory (based on this, I get the category) and multiple locations (based on each location, I should get the warehouse). In the edit mode, I’ve already managed to load the category based on the subcategory, but I can’t load the warehouses based on the locations. How could I do that? Thanks in advance.
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);
}
}
9 replies
FFilament
Created by demonshide on 1/8/2025 in #❓┊help
Sidebar Overlapping Navbar
No description
8 replies
FFilament
Created by demonshide on 9/3/2024 in #❓┊help
TitleAttribute doesn't appear in Form Select
No description
4 replies
FFilament
Created by demonshide on 9/1/2024 in #❓┊help
Form Select, titleAttribute does not appear
$query->doesntHave('test')
2 replies
FFilament
Created by demonshide on 8/31/2024 in #❓┊help
How should I use Filament in my system?
In my setup, users can have one of three roles: admin, doctor, or patient. Should I create a separate Admin PanelProvider for each role? Is that possible? My concern is that the default PanelProvider uses "admin" for its ID and path, so I'm wondering if I should create two additional providers with IDs and paths corresponding to each role. Or is it better and more recommended to use a single panel and restrict options based on roles, as is commonly done?
6 replies