You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
topnotch_website/app/Filament/Resources/OrderResource/Pages/EditOrder.php

56 lines
1.4 KiB
PHTML

2 months ago
<?php
namespace App\Filament\Resources\OrderResource\Pages;
use App\Enums\OrderAttributes;
2 months ago
use App\Filament\Resources\OrderResource;
1 month ago
use App\Models\Order;
2 months ago
use Filament\Actions;
1 month ago
use Filament\Actions\Action;
2 months ago
use Filament\Resources\Pages\EditRecord;
class EditOrder extends EditRecord
{
protected static string $resource = OrderResource::class;
protected function mutateFormDataBeforeFill(array $data): array
{
foreach (OrderAttributes::cases() as $case) {
if ($data[$case->name]) {
$data['order_attributes'][] = $case->value ?? null;
}
}
return $data;
}
protected function mutateFormDataBeforeSave(array $data): array
{
foreach (OrderAttributes::cases() as $case) {
$data[$case->name] = false;
}
$data['order_attributes'] = array_filter($data['order_attributes']);
foreach ($data['order_attributes'] as $attribute) {
$data[OrderAttributes::from($attribute)->name] = true;
}
unset($data['order_attributes']);
return $data;
}
2 months ago
protected function getHeaderActions(): array
{
return [
1 month ago
Action::make('print')
->icon('heroicon-s-printer')
->url(fn (Order $record) => route('orders.pdf', $record))
->openUrlInNewTab(),
Actions\DeleteAction::make()
->icon('heroicon-s-trash'),
2 months ago
];
}
}