laravel insert query 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 insert

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

Example 3: laravel not in query

DB::table(..)->select(..)->whereNotIn('book_price', [100,200])->get();

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

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

Tags:

Php Example