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
11 changes: 11 additions & 0 deletions src/Illuminate/Database/Concerns/BuildsQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ public function when($value, $callback, $default = null)
return $this;
}

/**
* Pass the query to a given callback.
*
* @param \Closure $callback
* @return \Illuminate\Database\Query\Builder
*/
public function tap($callback)
{
return $this->when(true, $callback);
}

/**
* Apply the callback's query changes if the given "value" is false.
*
Expand Down
11 changes: 0 additions & 11 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,17 +459,6 @@ public function crossJoin($table, $first = null, $operator = null, $second = nul
return $this;
}

/**
* Pass the query to a given callback.
*
* @param \Closure $callback
* @return \Illuminate\Database\Query\Builder
*/
public function tap($callback)
{
return $this->when(true, $callback);
}

/**
* Merge an array of where clauses and bindings.
*
Expand Down
17 changes: 17 additions & 0 deletions tests/Database/DatabaseConcernsBuildsQueriesTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Illuminate\Tests\Database;

use PHPUnit\Framework\TestCase;
use Illuminate\Database\Concerns\BuildsQueries;

class DatabaseConcernsBuildsQueriesTraitTest extends TestCase
{
public function testTapCallbackInstance()
{
$mock = $this->getMockForTrait(BuildsQueries::class);
$mock->tap(function ($builder) use ($mock) {
$this->assertEquals($mock, $builder);
});
}
}