Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Query/Grammars/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ public function compileUpdate(Builder $query, $values)
*/
public function prepareBindingsForUpdate(array $bindings, array $values)
{
$cleanBindings = Arr::except($bindings, ['join', 'select']);
$cleanBindings = Arr::except($bindings, ['select', 'join']);

return array_values(
array_merge($bindings['join'], $values, Arr::flatten($cleanBindings))
Expand Down
7 changes: 2 additions & 5 deletions src/Illuminate/Database/Query/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,10 @@ public function prepareBindingsForUpdate(array $bindings, array $values)
: $value;
})->all();

// Update statements with "joins" in Postgres use an interesting syntax. We need to
// take all of the bindings and put them on the end of this array since they are
// added to the end of the "where" clause statements as typical where clauses.
$bindingsWithoutJoin = Arr::except($bindings, 'join');
$cleanBindings = Arr::except($bindings, 'select');

return array_values(
array_merge($values, $bindings['join'], Arr::flatten($bindingsWithoutJoin))
array_merge($values, Arr::flatten($cleanBindings))
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Query/Grammars/SQLiteGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,10 @@ public function compileUpdate(Builder $query, $values)
*/
public function prepareBindingsForUpdate(array $bindings, array $values)
{
$cleanBindings = Arr::except($bindings, ['select', 'join']);
$cleanBindings = Arr::except($bindings, 'select');

return array_values(
array_merge($values, $bindings['join'], Arr::flatten($cleanBindings))
array_merge($values, Arr::flatten($cleanBindings))
);
}

Expand Down
7 changes: 2 additions & 5 deletions src/Illuminate/Database/Query/Grammars/SqlServerGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,10 @@ protected function parseUpdateTable($table)
*/
public function prepareBindingsForUpdate(array $bindings, array $values)
{
// Update statements with joins in SQL Servers utilize an unique syntax. We need to
// take all of the bindings and put them on the end of this array since they are
// added to the end of the "where" clause statements as typical where clauses.
$bindingsWithoutJoin = Arr::except($bindings, 'join');
$cleanBindings = Arr::except($bindings, 'select');

return array_values(
array_merge($values, $bindings['join'], Arr::flatten($bindingsWithoutJoin))
array_merge($values, Arr::flatten($cleanBindings))
);
}

Expand Down
5 changes: 5 additions & 0 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1995,6 +1995,11 @@ public function testUpdateMethodWithoutJoinsOnPostgres()
$builder->getConnection()->shouldReceive('update')->once()->with('update "users" set "email" = ?, "name" = ? where "id" = ?', ['foo', 'bar', 1])->andReturn(1);
$result = $builder->from('users')->where('id', '=', 1)->update(['users.email' => 'foo', 'name' => 'bar']);
$this->assertEquals(1, $result);

$builder = $this->getPostgresBuilder();
$builder->getConnection()->shouldReceive('update')->once()->with('update "users" set "email" = ?, "name" = ? where "id" = ?', ['foo', 'bar', 1])->andReturn(1);
$result = $builder->from('users')->where('id', '=', 1)->selectRaw('?', ['ignore'])->update(['users.email' => 'foo', 'name' => 'bar']);
$this->assertEquals(1, $result);
}

public function testUpdateMethodWithJoinsOnPostgres()
Expand Down