1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @author Eddy <[email protected]> |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace App\Repository\Admin; |
7
|
|
|
|
8
|
|
|
use App\Model\Admin\SensitiveWord; |
9
|
|
|
use App\Repository\Searchable; |
10
|
|
|
|
11
|
|
|
class SensitiveWordRepository |
12
|
|
|
{ |
13
|
|
|
use Searchable; |
14
|
|
|
|
15
|
|
|
public static function list($perPage, $condition = []) |
16
|
|
|
{ |
17
|
|
|
$data = SensitiveWord::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
|
|
|
$item->editUrl = route('admin::SensitiveWord.edit', ['id' => $item->id]); |
25
|
|
|
$item->deleteUrl = route('admin::SensitiveWord.delete', ['id' => $item->id]); |
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 SensitiveWord::query()->create($data); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public static function update($id, $data) |
43
|
|
|
{ |
44
|
|
|
return SensitiveWord::query()->where('id', $id)->update($data); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public static function find($id) |
48
|
|
|
{ |
49
|
|
|
return SensitiveWord::query()->find($id); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public static function delete($id) |
53
|
|
|
{ |
54
|
|
|
return SensitiveWord::destroy($id); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public static function exist($condition) |
58
|
|
|
{ |
59
|
|
|
return SensitiveWord::where($condition)->first(); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|