1 | <?php |
||
2 | namespace Magros\Encryptable; |
||
3 | |||
4 | use Illuminate\Database\ConnectionInterface; |
||
5 | use Illuminate\Database\Query\Builder; |
||
6 | |||
7 | class EncryptableQueryBuilder extends Builder { |
||
8 | |||
9 | private $model; |
||
10 | |||
11 | /** |
||
12 | * EncryptableQueryBuilder constructor. |
||
13 | * @param ConnectionInterface $connection |
||
14 | * @param Encryptable $model |
||
15 | */ |
||
16 | public function __construct(ConnectionInterface $connection, $model) |
||
17 | { |
||
18 | parent::__construct($connection, $connection->getQueryGrammar(), $connection->getPostProcessor()); |
||
19 | $this->model = $model; |
||
20 | } |
||
21 | |||
22 | /** |
||
23 | * @param array|\Closure|string $column |
||
24 | * @param null $operator |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
25 | * @param null $value |
||
0 ignored issues
–
show
|
|||
26 | * @param string $boolean |
||
27 | * @return Builder |
||
28 | * @throws \Exception |
||
29 | */ |
||
30 | public function where($column, $operator = null, $value = null, $boolean = 'and') |
||
31 | { |
||
32 | if (method_exists($this->model, 'encryptable') && $this->model->encryptable($column)) { |
||
33 | list($value, $operator) = $this->prepareValueAndOperator($value, $operator, func_num_args() === 2); |
||
34 | $value = $this->model->encryptAttribute($value); |
||
35 | } |
||
36 | |||
37 | return parent::where($column, $operator, $value, $boolean); |
||
38 | |||
39 | } |
||
40 | } |