-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement higher order orWhere for simpler scopes
- Loading branch information
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Illuminate\Support; | ||
|
||
use Illuminate\Database\Eloquent\Builder; | ||
|
||
/** | ||
* @mixin \Illuminate\Database\Eloquent\Builder | ||
*/ | ||
class HigherOrderBuilderProxy | ||
{ | ||
/** | ||
* The collection being operated on. | ||
* | ||
* @var \Illuminate\Database\Eloquent\Builder | ||
*/ | ||
protected $builder; | ||
|
||
/** | ||
* The method being proxied. | ||
* | ||
* @var string | ||
*/ | ||
protected $method; | ||
|
||
/** | ||
* Create a new proxy instance. | ||
* | ||
* @param Builder $builder | ||
* @param string $method | ||
*/ | ||
public function __construct(Builder $builder, $method) | ||
{ | ||
$this->method = $method; | ||
$this->builder = $builder; | ||
} | ||
|
||
/** | ||
* Proxy a scope call onto the query builder. | ||
* | ||
* @param string $method | ||
* @param array $parameters | ||
* @return mixed | ||
*/ | ||
public function __call($method, $parameters) | ||
{ | ||
return $this->builder->{$this->method}(function ($value) use ($method, $parameters) { | ||
return $value->{$method}(...$parameters); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters