laravel insert into table code example

Example 1: laravel insert

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

Example 2: laravel join table

$users = DB::table('users')
            ->join('contacts', 'users.id', '=', 'contacts.user_id')
            ->join('orders', 'users.id', '=', 'orders.user_id')
            ->select('users.*', 'contacts.phone', 'orders.price')
            ->get();

Example 3: laravel create db table

php artisan make:migration create_users_table

Example 4: insert into laravel 8

DB::insert('insert into users (id, name) values (?, ?)', [1, 'Dayle']);

Tags:

Php Example