Completed
Push — master ( 5c5f39...09f73b )
by Mahmoud
03:29
created

RoleCriteria::apply()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace App\Containers\User\Data\Criterias;
4
5
use App\Port\Criteria\Abstracts\Criteria;
6
use Prettus\Repository\Contracts\RepositoryInterface as PrettusRepositoryInterface;
7
8
/**
9
 * Class RoleCriteria.
10
 *
11
 * @author  Mahmoud Zalt <[email protected]>
12
 */
13
class RoleCriteria extends Criteria
14
{
15
16
    /**
17
     * @var string
18
     */
19
    private $roles;
20
21
    /**
22
     * RoleCriteria constructor.
23
     *
24
     * @param $roles
25
     */
26
    public function __construct($roles)
27
    {
28
        $this->roles = $roles;
29
    }
30
31
    /**
32
     * @param                                                   $model
33
     * @param \Prettus\Repository\Contracts\RepositoryInterface $repository
34
     *
35
     * @return mixed
36
     */
37
    public function apply($model, PrettusRepositoryInterface $repository)
38
    {
39
        return $model->whereHas('roles', function ($q) {
40
            $q->where('name', $this->roles);
41
        });
42
    }
43
}
44