laravel query() code example

Example 1: laravel update from query

$affected = DB::table('users')
              ->where('id', 1)
              ->update(['votes' => 1]);

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 wher in

$users = DB::table('users')
                    ->whereIn('id', [1, 2, 3])
                    ->get();

Example 4: laravel db::query update

DB::table('user')->where('email', $userEmail)->update(array('member_type' => $plan));

Example 5: Laravel query where and

Table::where('Column', Value)->where('NewColumn', Value)->get();

Example 6: laravel find query

php artisan make:model Flight --migration

php artisan make:model Flight -m

Tags:

Php Example