- Introduce CreateRecordTransactionsAction to handle transaction creation for any model - Introduce SyncAccountsAction to encapsulate account synchronization logic - Refactor CreateSaleAction to use new actions and handle full sale creation flow - Simplify CreateExpense and CreateSale pages by delegating to actions - Ensure proper transaction handling with database rollback on failure
17 lines
334 B
PHP
17 lines
334 B
PHP
<?php
|
|
|
|
namespace App\Actions\Sales;
|
|
|
|
use App\Models\Sale;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class SyncAccountsAction
|
|
{
|
|
public function __invoke(Sale $sale, array $accounts): void
|
|
{
|
|
DB::transaction(function () use ($sale, $accounts) {
|
|
$sale->accounts()->sync($accounts);
|
|
}, attempts: 2);
|
|
}
|
|
}
|