laravel query builder insert code example

Example 1: laravel query builder data insert

use Illuminate\Support\Facades\DB;//use it above
use Illuminate\Support\Facades\Hash;   //Hash for password || use it above

public function create(Request $request)
    {
        DB::table('students')->insert([
            'email' =>  $request->email,
            'password' =>  Hash::make($request->password),
            'address' =>  $request->address,
            'address2' =>  $request->address2,
            'city' =>  $request->city,
            'country' =>  $request->country,
            'zip' =>  $request->zip,
        ]);
        return redirect('create');
    }

Example 2: laravel wher in

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

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

DB::select('SELECT * FROM users WHERE name = "'.Input::get('name').'"');

Example 4: laravel having

$users = DB::table('users')
                ->groupBy('account_id')
                ->having('account_id', '>', 100)
                ->get();

Tags:

Php Example