LogRepository::list()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 14
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 19
rs 9.7998
1
<?php
2
/**
3
 * @author  Eddy <[email protected]>
4
 */
5
6
namespace App\Repository\Admin;
7
8
use App\Model\Admin\Log;
9
use App\Repository\Searchable;
10
11
class LogRepository
12
{
13
    use Searchable;
14
15
    public static function list($perPage, $condition = [])
16
    {
17
        $data = Log::query()
18
            ->where(function ($query) use ($condition) {
19
                Searchable::buildQuery($query, $condition);
20
            })
21
            ->orderBy('id', 'desc')
22
            ->paginate($perPage);
23
        $data->transform(function ($item) {
24
            // 因列表展示用的layui table组件未进行xss处理,故在后端进行xss处理
25
            xssFilter($item);
26
            return $item;
27
        });
28
29
        return [
30
            'code' => 0,
31
            'msg' => '',
32
            'count' => $data->total(),
33
            'data' => $data->items(),
34
        ];
35
    }
36
37
    public static function add($data)
38
    {
39
        return Log::query()->create($data);
40
    }
41
42
    public static function find($id)
43
    {
44
        return Log::query()->find($id);
45
    }
46
}
47