laravel/framework — pull request #1983 by felixkiss (2013-07-31 10:11:00+00:00)
Title: Make sure the order of fields is correct on batch inserts. Fixes laravel/laravel#2220

If you try to insert multiple records using Illuminate\Database\Query\Builder->insert()
things can get mixed up if any of your records keys are in the wrong order.

E.g. assuming an attempt to insert like
```php
$users = array(
array(
'email' => 'foo',
'name' => 'taylor',
),
array(
'name' => 'dayle'
'email' => 'bar',
),
);
DB::table('users')->insert($users);
```

this will generate a SQL query like
```sql
insert into "users" ("email", "name") select ? as "email", ? as "name" union select ? as "email", ? as "name"
```
with bindings like
```php
array(
'foo',
'taylor',
'dayle',
'bar',
)
```

This will lead to the following situation in the database:
```
+-------+--------+
| email | name |
+-------+--------+
| foo | taylor |
| dayle | bar |
+-------+--------+
```

This change will fix this problem by sorting the records to be inserted before the
SQL query is generated.