demonshide
demonshide
FFilament
Created by demonshide on 2/3/2025 in #❓┊help
How to Edit the Data of a Repeater
I tested the methods mutateRelationshipDataBeforeSaveUsing(), mutateRelationshipDataBeforeFillUsing(), and mutateRelationshipDataBeforeCreateUsing() in the Filament demo. I tested them in App\Filament\Resources\Shop\OrderResource. On line 357, I added:
->mutateRelationshipDataBeforeSaveUsing(function (array $data): array {
// $data['user_id'] = auth()->id();
dd($data);
// return $data;
})
->mutateRelationshipDataBeforeFillUsing(function (array $data): array {
// $data['user_id'] = auth()->id();
dd($data);
// return $data;
})
->mutateRelationshipDataBeforeSaveUsing(function (array $data): array {
// $data['user_id'] = auth()->id();
dd($data);
// return $data;
})
->mutateRelationshipDataBeforeFillUsing(function (array $data): array {
// $data['user_id'] = auth()->id();
dd($data);
// return $data;
})
And it always returns only the data from the first item of the repeater, like this:
array:8 [
"id" => 14
"shop_order_id" => 4
"shop_product_id" => 33
"qty" => 6
"unit_price" => 145.27
"created_at" => "2025-02-06T20:04:44.000000Z"
"updated_at" => "2025-02-06T20:04:44.000000Z"
"sort" => 0
]
array:8 [
"id" => 14
"shop_order_id" => 4
"shop_product_id" => 33
"qty" => 6
"unit_price" => 145.27
"created_at" => "2025-02-06T20:04:44.000000Z"
"updated_at" => "2025-02-06T20:04:44.000000Z"
"sort" => 0
]
Even though there are several items, it only returns 1, and it is always the first item of all.
9 replies
FFilament
Created by demonshide on 2/3/2025 in #❓┊help
How to Edit the Data of a Repeater
Thank you very much, I did this to test:
Repeater::make('locations')
->schema([
Select::make('warehouse_id'),
Select::make('location_id'),
])
->mutateRelationshipDataBeforeSaveUsing(function (array $data): array {
dd($data); // <---
// return $data;
})
...,
Repeater::make('locations')
->schema([
Select::make('warehouse_id'),
Select::make('location_id'),
])
->mutateRelationshipDataBeforeSaveUsing(function (array $data): array {
dd($data); // <---
// return $data;
})
...,
I added several records in the repeater, so I expected to see something like this:
"locations" => [
[
"warehouse_id" => "1",
"location_id" => "2",
],
[
"warehouse_id" => "2",
"location_id" => "5",
],
...
]
"locations" => [
[
"warehouse_id" => "1",
"location_id" => "2",
],
[
"warehouse_id" => "2",
"location_id" => "5",
],
...
]
But it only shows this:
array:2 [// app\Filament\Resources\ProductResource.php:141
"warehouse_id" => "1"
"location_id" => "2"
]
array:2 [// app\Filament\Resources\ProductResource.php:141
"warehouse_id" => "1"
"location_id" => "2"
]
Meaning, it only shows the first one and seems to ignore the rest. I also tried altering it:
Repeater::make('locations')
->mutateRelationshipDataBeforeFillUsing(function (array $data): array {
$data['warehouse_id'] = '2';
$data['location_id'] = '5';
// dd($data);
return $data;
})
Repeater::make('locations')
->mutateRelationshipDataBeforeFillUsing(function (array $data): array {
$data['warehouse_id'] = '2';
$data['location_id'] = '5';
// dd($data);
return $data;
})
And what I achieved was that when editing, every record in the repeater gets set to those values.
9 replies
FFilament
Created by demonshide on 2/3/2025 in #❓┊help
How to Edit the Data of a Repeater
I tried to analyze how the data from a repeater is sent, but I realized that when I click 'create', only the base model data is sent, and I don’t see the repeater data or that many-to-many relationship.
class CreateProduct extends CreateRecord
{
protected static string $resource = ProductResource::class;

protected function mutateFormDataBeforeCreate(array $data): array
{
dd($data); // <----
return $data;
}
}
class CreateProduct extends CreateRecord
{
protected static string $resource = ProductResource::class;

protected function mutateFormDataBeforeCreate(array $data): array
{
dd($data); // <----
return $data;
}
}
9 replies
FFilament
Created by demonshide on 1/8/2025 in #❓┊help
Sidebar Overlapping Navbar
Yes, I am using the latest version, ^3.2, and I did run npm run build. But what I realized is that it's not just happening to me, the demo project of Filament also has the same issue.
8 replies
FFilament
Created by demonshide on 9/3/2024 in #❓┊help
TitleAttribute doesn't appear in Form Select
I found out I can use $record to access the current resource and successfully updated the query. I'm really sorry for the trouble and thank you so much for your help.
4 replies
FFilament
Created by demonshide on 8/31/2024 in #❓┊help
How should I use Filament in my system?
I get it, thank you
6 replies