RoleRepository   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 50
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 3 1
A find() 0 3 1
A update() 0 3 1
A list() 0 20 1
A exist() 0 3 1
A add() 0 3 1
1
<?php
2
/**
3
 * Date: 2019/2/25 Time: 16:15
4
 *
5
 * @author  Eddy <[email protected]>
6
 * @version v1.0.0
7
 */
8
9
namespace App\Repository\Admin;
10
11
use Spatie\Permission\Models\Role;
12
use App\Repository\Searchable;
13
14
class RoleRepository
15
{
16
    use Searchable;
17
18
    public static function list($perPage, $condition = [])
19
    {
20
        $data = Role::query()
21
            ->where(function ($query) use ($condition) {
22
                Searchable::buildQuery($query, $condition);
23
            })
24
            ->orderBy('id', 'desc')
25
            ->paginate($perPage);
26
        $data->transform(function ($item) {
27
            xssFilter($item);
28
            $item->editUrl = route('admin::role.edit', ['id' => $item->id]);
29
            $item->permissionUrl = route('admin::role.permission.edit', ['id' => $item->id]);
30
            return $item;
31
        });
32
33
        return [
34
            'code' => 0,
35
            'msg' => '',
36
            'count' => $data->total(),
37
            'data' => $data->items(),
38
        ];
39
    }
40
41
    public static function add($data)
42
    {
43
        return Role::query()->create($data);
44
    }
45
46
    public static function update($id, $data)
47
    {
48
        return Role::query()->where('id', $id)->update($data);
49
    }
50
51
    public static function find($id)
52
    {
53
        return Role::query()->find($id);
54
    }
55
56
    public static function all()
57
    {
58
        return Role::all();
59
    }
60
61
    public static function exist($name)
62
    {
63
        return Role::query()->where('name', $name)->first();
64
    }
65
}
66