BaseRepository   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A whereInAndOrderBy() 0 8 1
A get() 0 4 1
1
<?php
2
3
/**
4
 * Created by PhpStorm.
5
 * User: xuan
6
 * Date: 9/21/15
7
 * Time: 6:30 PM.
8
 */
9
namespace PHPHub\Repositories\Eloquent;
10
11
use DB;
12
use PHPHub\Repositories\Eloquent\Traits\AutoWithTrait;
13
use PHPHub\Repositories\Eloquent\Traits\WithOnlyTrait;
14
use Prettus\Repository\Eloquent\BaseRepository as Repository;
15
use Illuminate\Container\Container as Application;
16
use Illuminate\Support\Collection;
17
18
abstract class BaseRepository extends Repository
19
{
20
    use WithOnlyTrait, AutoWithTrait;
21
22
    /**
23
     * @param Application $app
24
     */
25
    public function __construct(Application $app)
26
    {
27
        $this->app = $app;
28
        $this->criteria = new Collection();
29
        $this->makeModel();
30
        $this->makeValidator();
31
        $this->boot();
32
    }
33
34
    /**
35
     * whereIn 查询并按照数组内数据排序.
36
     *
37
     * @param array  $data
38
     * @param string $column
39
     *
40
     * @return $this
41
     */
42
    public function whereInAndOrderBy(array $data, $column = 'id')
43
    {
44
        $this->model = $this->model
45
            ->whereIn('id', $data)
46
            ->orderByRaw(DB::raw("FIELD($column, ".implode(',', $data).')'));
47
48
        return $this;
49
    }
50
51
    public function get()
52
    {
53
        return $this->model->get();
54
    }
55
}
56