laravel DB::INSERT 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: laravel select count
$count = DB::table('category_issue')->count();
Example 4: laravel find query
$flight = App\Models\Flight::find(1);
$flight = App\Models\Flight::where('active', 1)->first();
$flight = App\Models\Flight::firstWhere('active', 1);