Passed
Push — master ( 62919d...1f65fa )
by Iman
04:23
created

ApiKeysRepository::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Crocodicstudio\Crudbooster\Modules\ApiGeneratorModule;
4
5
use Illuminate\Support\Facades\DB;
6
7
class ApiKeysRepository
8
{
9
    public function incrementHit($serverSecret)
10
    {
11
        return $this->where(['secretkey' => $serverSecret])->increment('hit');
12
    }
13
14
    public function where($where)
15
    {
16
        return $this->table()->where($where);
17
    }
18
19
    private static function table()
20
    {
21
        return DB::table('cms_apikey');
22
    }
23
24
    public function getSecretKeys()
25
    {
26
        return $this->where(['status' => 'active'])->pluck('secretkey');
27
    }
28
29
    public function get()
30
    {
31
        return $this->table()->get();
32
    }
33
34
    public function deleteById($id)
35
    {
36
        return $this->where(['id' => $id])->delete();
37
    }
38
39
    public function updateById($status, $id)
40
    {
41
        return $this->where(['id' => $id])->update(['status' => $status]);
42
    }
43
44
    public function insertGetId($token)
45
    {
46
        return $this->table()->insertGetId([
47
            'secretkey' => $token,
48
            'created_at' => YmdHis(),
49
            'status' => 'active',
50
            'hit' => 0,
51
        ]);
52
    }
53
}