38 lines
916 B
PHP
38 lines
916 B
PHP
<?php
|
|
|
|
namespace App\Filament\User\Resources\ProductResource\Pages;
|
|
|
|
use App\Filament\User\Resources\ProductResource;
|
|
use Filament\Actions;
|
|
use Filament\Resources\Pages\EditRecord;
|
|
|
|
class EditProduct extends EditRecord
|
|
{
|
|
protected static string $resource = ProductResource::class;
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
Actions\DeleteAction::make(),
|
|
];
|
|
}
|
|
|
|
protected function afterSave(): void {
|
|
$this->syncSizes();
|
|
}
|
|
|
|
protected function syncSizes(): void {
|
|
$product = $this->record;
|
|
|
|
$sizes = collect($this->data['sizes'] ?? [])
|
|
->mapWithKeys(function ($size) {
|
|
return [
|
|
$size['packing_id'] => ['description' => $size['description'], 'price' =>$size['price']],
|
|
];
|
|
})
|
|
->toArray();
|
|
|
|
$product->sizes()->sync($sizes);
|
|
}
|
|
}
|