laravel 8 insert into database code example
Example 1: TRANSACTON LARAVEL QUERY BUILDER
DB::beginTransaction();
try {
DB::insert(...);
DB::commit();
} catch (\Throwable $e) {
DB::rollback();
throw $e;
}
Example 2: laravel db inserr
$id = DB::table('users')->insertGetId(
['email' => '[email protected]', 'votes' => 0]
);