“Transaction db laravel” Réponses codées

Transactions Laravel

DB::beginTransaction();

try {
    DB::insert(...);
    DB::insert(...);
    DB::insert(...);

    DB::commit();
    // all good
} catch (\Exception $e) {
    DB::rollback();
    // something went wrong
}
404 Not Found

Transaction du modèle Laravel

DB::beginTransaction();
        try {
            $project = Project::find($id);
            $project->users()->detach();
            $project->delete();
            DB::commit();
        } catch (\Exception $ex) {
            DB::rollback();
            return response()->json(['error' => $ex->getMessage()], 500);
        }
Shadow

DB :: Transaction

use Illuminate\Support\Facades\DB;

DB::transaction(function () {
    DB::update('update users set votes = 1');

    DB::delete('delete from posts');
});
Terrible Teira

Transaction db laravel

DB::beginTransaction();

try {
    DB::insert(...);    
    DB::commit();
} catch (\Exception $e) {
    DB::rollback();
    throw $e;
} catch (\Throwable $e) {
    DB::rollback();
    throw $e;
}
Mohamad

Transacton Laravel Query Builder

DB::beginTransaction();

try {
    DB::insert(...);    
    DB::commit();
} catch (\Throwable $e) {
    DB::rollback();
    throw $e;
}
Brainy Booby

transaction laravel

DB::beginTransaction();
try { /** Statement */   DB::commit(); } 
catch (\Exception $e) { /** Statement if failed */ DB::rollback(); }
mr.dar

Réponses similaires à “Transaction db laravel”

Questions similaires à “Transaction db laravel”

Plus de réponses similaires à “Transaction db laravel” dans PHP

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code