laravel/framework — pull request #6465 by stristr (2014-11-20 22:21:47+00:00)
Title: Join bindings multiply when a query is executed multiple times

I encountered this bug when a query using a complex join containing inner bindings was used with the Paginator. When the query grammar compiles the complex join, it adds its bindings to the main query without unsetting the bindings from the join. The result is running toSql() multiple times causes the number of bindings to increase.

This is actually a major bug because RDBMSes won't even execute the query when the binding count doesn't match the number of bindings in the prepared statement.

Please see failing unit test and fix below.