laravel/framework — pull request #5748 by stidges (2014-09-15 21:57:57+00:00)
Title: [4.2] Eloquent BelongsToMany Pivot Timestamps

This pull request fixes an issue with timestamps that occur on pivot tables when using the Eloquent BelongsToMany relationship.

**The Issue**

In the BelongsToMany relationship class there is an explicit check for the existence of the 'created_at' column on the pivot table. Once this check is passed, 'created_at' and 'updated_at' are **both** assigned. This introduces the following issues:

- Pivot tables that contain *only* a 'created_at' column will receive an error upon attaching. This is because the 'updated_at' column is also set, which doesn't exist.
- Pivot tables that contain *only* an 'updated_at' column will not have their 'updated_at' timestamps updated. This is because if no 'created_at' column is set in the pivot columns, the whole timestamp process is skipped.

**What This PR Changes**

This PR adds an extra condition to the `createAttachRecords` method, allowing for more flexibility in the usage of timestamps. This allows the 'created_at' and 'updated_at' column to be used both in combination or separately. It also adds extra checks in the `setTimestampsOnAttach` to check if the 'created_at' or 'updated_at' exists before assigning it.