diff --git a/app/Models/EntityModel.php b/app/Models/EntityModel.php index b8e7d651ada4..9483f84a8c6a 100644 --- a/app/Models/EntityModel.php +++ b/app/Models/EntityModel.php @@ -27,6 +27,7 @@ class EntityModel extends Eloquent $lastEntity = $className::withTrashed() ->scope(false, $entity->account_id) ->orderBy('public_id', 'DESC') + ->lockForUpdate() ->first(); if ($lastEntity) { diff --git a/app/Ninja/Repositories/ClientRepository.php b/app/Ninja/Repositories/ClientRepository.php index 3e43d8f34f5f..ab9789f1cae9 100644 --- a/app/Ninja/Repositories/ClientRepository.php +++ b/app/Ninja/Repositories/ClientRepository.php @@ -66,6 +66,8 @@ class ClientRepository extends BaseRepository { $publicId = isset($data['public_id']) ? $data['public_id'] : false; + DB::beginTransaction(); + if (!$publicId || $publicId == '-1') { $client = Client::createNew(); } else { @@ -75,6 +77,9 @@ class ClientRepository extends BaseRepository $client->fill($data); $client->save(); + DB::commit(); + + /* if ( ! isset($data['contact']) && ! isset($data['contacts'])) { return $client;