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
This commit is contained in:
16
app/Actions/Sales/SyncAccountsAction.php
Normal file
16
app/Actions/Sales/SyncAccountsAction.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user