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.
43 lines
978 B
PHP
43 lines
978 B
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\InvoiceResource\Pages;
|
|
|
|
use App\Filament\Resources\InvoiceResource;
|
|
use App\Models\Invoice;
|
|
use App\Models\Order;
|
|
use Filament\Actions;
|
|
use Filament\Resources\Pages\EditRecord;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class EditInvoice extends EditRecord
|
|
{
|
|
protected static string $resource = InvoiceResource::class;
|
|
|
|
protected function mutateFormDataBeforeFill(array $data): array
|
|
{
|
|
$invoice = Invoice::findOrFail($data['id']);
|
|
|
|
foreach ($invoice->orders as $order) {
|
|
$data['orders'][] = $order->id;
|
|
}
|
|
|
|
return $data;
|
|
}
|
|
|
|
protected function handleRecordUpdate(Model $record, array $data): Model
|
|
{
|
|
$record->orders()->delete();
|
|
|
|
$record->orders()->saveMany(Order::findMany($data['orders']));
|
|
|
|
return $record;
|
|
}
|
|
|
|
protected function getHeaderActions(): array
|
|
{
|
|
return [
|
|
Actions\DeleteAction::make(),
|
|
];
|
|
}
|
|
}
|