adrema/app/Invoice/Actions/InvoiceStoreAction.php

26 lines
591 B
PHP
Raw Permalink Normal View History

2023-12-13 00:35:39 +01:00
<?php
namespace App\Invoice\Actions;
use Lorisleiva\Actions\ActionRequest;
use Lorisleiva\Actions\Concerns\AsAction;
use App\Invoice\Models\Invoice;
2023-12-16 23:53:18 +01:00
use App\Lib\Events\Succeeded;
2023-12-13 00:35:39 +01:00
class InvoiceStoreAction
{
use AsAction;
2023-12-17 00:45:03 +01:00
use HasValidation;
2023-12-13 00:35:39 +01:00
public function handle(ActionRequest $request): void
{
$invoice = Invoice::create($request->safe()->except('positions'));
foreach ($request->validated('positions') as $position) {
$invoice->positions()->create($position);
}
2023-12-16 23:53:18 +01:00
Succeeded::message('Rechnung erstellt.')->dispatch();
2023-12-13 00:35:39 +01:00
}
}