Completed
Push — master ( 5c46bf...f77784 )
by Mahmoud
03:22
created

ThisUserCriteria::apply()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
3
namespace App\Port\Criteria\Eloquent;
4
5
use App\Port\Criteria\Abstracts\Criteria;
6
use Illuminate\Support\Facades\Auth;
7
use Prettus\Repository\Contracts\RepositoryInterface as PrettusRepositoryInterface;
8
9
/**
10
 * Class ThisUserCriteria.
11
 *
12
 * @author  Mahmoud Zalt <[email protected]>
13
 */
14
class ThisUserCriteria extends Criteria
15
{
16
    /**
17
     * @var int
18
     */
19
    private $userId;
20
21
    /**
22
     * ThisUserCriteria constructor.
23
     *
24
     * @param $userId
25
     */
26
    public function __construct($userId = null)
27
    {
28
        $this->userId = $userId;
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
        if(!$this->userId){
40
            $this->userId = Auth::user()->id;
41
        }
42
43
        return $model->where('user_id', '=', $this->userId);
44
    }
45
}
46