DB query in laravel code example

Example 1: wherein laravel

DB::table('user')->whereIn('id', [100,200])->get();

Example 2: laravel sql query

use Illuminate\Support\Facades\DB;

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

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

Example 3: laravel db query

$users = DB::table('users')
            ->where('votes', '>', 100)
            ->orWhere(function($query) {
                $query->where('name', 'Abigail')
                      ->where('votes', '>', 50);
            })
            ->get();

Example 4: DB::table('users')->get();

$users = DB::table('users')->get();

Example 5: DB::table('users')->get();

DB::select('SELECT * FROM users WHERE name = ?', array(Input::get('name')));

Example 6: laravel db inserr

DB::table('users')->insert([
    ['email' => '[email protected]', 'votes' => 0],
    ['email' => '[email protected]', 'votes' => 0],
]);

Tags:

Sql Example