1
私のテーブルの列... Laravel - DBを挿入::ロールバックユニークキー防止<strong>が</strong>列がユニークに設定されたentry_id
は私の変数を変更する&キャッチし、DB ::ロールバックを試してみ使用する任意の最善の方法はあります?例えば:まず、時間がエラーを持っていないでしょう$_id = 1
$entryId = 'test0000'+$_id;
DB::beginTransaction();
try {
$sub = Submission::create([
'entry_id' => $entryId,
]);
DB::commit();
// success insert..
} catch (\Exception $e) {
DB::rollback();
//detected unique... just ++ _id to ensure not unique
$_id++;
// throw $e;
} catch (\Throwable $e) {
DB::rollback();
//detected unique... just ++ _id to ensure not unique
$_id++;
// throw $e;
}
、私は第二の時間を知っている可能性があり、はをしたentry_id確保することができ、私はエントリ++ rollbackメソッドを使用して、ユニークではないでしょうか?これは正しい方法ですか?
ありがとうございました!