raw queries in laravel
snippet in php

raw queries in laravel

user9729

DB::statement('UPDATE users SET role_id = 1 WHERE role_id IS NULL AND YEAR(created_at) > 2020');

laravel sql query

user2500

use Illuminate\Support\Facades\DB;

$users = DB::select('select * from users');

foreach ($users as $user) {
    echo $user->name;
}

DB: in eloquent using sql

user3239

$results = DB::select('select * from users where id = :id', ['id' => 1]);