Files
MKM/app/Actions/Sales/SyncAccountsAction.php
Jp 7bcfaff311 refactor: extract transaction creation and account syncing to actions
- 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
2026-02-16 01:48:25 +08:00

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);
}
}