laravel execute sql query code example
Example 1: laravel sql query
use Illuminate\Support\Facades\DB;
$users = DB::select('select * from users');
foreach ($users as $user) {
echo $user->name;
}
Example 2: DB: in eloquent using sql
$results = DB::select('select * from users where id = :id', ['id' => 1]);