Erster Upload
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\User\Resources\ProductResource\Pages;
|
||||
|
||||
use App\Filament\User\Resources\ProductResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\ProductSize;
|
||||
|
||||
class CreateProduct extends CreateRecord
|
||||
{
|
||||
protected static string $resource = ProductResource::class;
|
||||
|
||||
protected function handleRecordCreation(array $data): Model {
|
||||
|
||||
$record = static::getModel()::create($data);
|
||||
|
||||
foreach ($data['sizes'] as $size) {
|
||||
ProductSize::create([
|
||||
'product_id' => $record->id,
|
||||
'packing_id' => $size['packing_id'],
|
||||
'description' => $size['description'],
|
||||
'price' => $size['price'],
|
||||
]);
|
||||
}
|
||||
return $record;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\User\Resources\ProductResource\Pages;
|
||||
|
||||
use App\Filament\User\Resources\ProductResource;
|
||||
use Filament\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListProducts extends ListRecords
|
||||
{
|
||||
protected static string $resource = ProductResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user