WhereRelationFieldIn::apply()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace OkayBueno\Repositories\Criteria\Eloquent;
4
5
use OkayBueno\Repositories\Criteria\CriteriaInterface;
6
7
/**
8
 * Class WhereRelationFieldIn
9
 * @package OkayBueno\Repositories\Criteria\Eloquent
10
 */
11
class WhereRelationFieldIn implements CriteriaInterface
12
{
13
    protected $list = [];
14
    protected $relationName;
15
    protected $field = 'id';
16
17
    /**
18
     * WhereMoodsIn constructor.
19
     * @param $relationName
20
     * @param array $list
21
     * @param string $field
22
     */
23
    public function __construct(  $relationName, array $list, $field = 'id' )
24
    {
25
        $this->relationName = $relationName;
26
        $this->list = $list;
27
        $this->field = $field;
28
    }
29
30
    /**
31
     * @param mixed $queryBuilder
32
     * @return mixed
33
     */
34
    public function apply( $queryBuilder )
35
    {
36
        // Do something with the query builder and return it.
37
        return $queryBuilder->whereHas( $this->relationName, function ($query) {
38
            $query->whereIn( $this->field, $this->list);
39
        });
40
    }
41
42
}
43