laravel insert data code example
Example 1: laravel insert
DB::table('users')->insert([
'email' => '[email protected]',
'votes' => 0
]);
Example 2: TRANSACTON LARAVEL QUERY BUILDER
DB::beginTransaction();
try {
DB::insert(...);
DB::commit();
} catch (\Throwable $e) {
DB::rollback();
throw $e;
}
Example 3: sql insert data
INSERT INTO users (first_name, last_name, address, email)
VALUES (‘Tester’, ‘Jester’, ‘123 Fake Street, Sheffield, United
Kingdom’, ‘[email protected]’);