1 | <?php |
||
2 | |||
3 | namespace HayriCan\IpChecker; |
||
4 | |||
5 | /** |
||
6 | * Laravel IP Checker |
||
7 | * |
||
8 | * @author Hayri Can BARÇIN <hayricanbarcin (#) gmail (.) com> |
||
9 | * @license http://www.opensource.org/licenses/mit-license.php MIT |
||
10 | * @link https://github.com/HayriCan/laravel-ip-checker |
||
11 | */ |
||
12 | |||
13 | use HayriCan\IpChecker\Contracts\IpCheckerInterface; |
||
14 | |||
15 | class DBDriver implements IpCheckerInterface{ |
||
16 | |||
17 | /** |
||
18 | * Model for saving logs |
||
19 | * |
||
20 | * @var [type] |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
21 | */ |
||
22 | protected $model; |
||
23 | protected $ipList = []; |
||
24 | |||
25 | public function __construct(IpList $ipList) |
||
26 | { |
||
27 | $this->model = $ipList; |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * @return array |
||
32 | */ |
||
33 | public function getIpArray() |
||
34 | { |
||
35 | foreach ($this->model->all() as $record){ |
||
36 | array_push($this->ipList,$record->ip); |
||
37 | } |
||
38 | $ipList = $this->ipList ?? []; |
||
39 | |||
40 | return $ipList; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @return IpList[]|\Illuminate\Database\Eloquent\Collection|mixed |
||
45 | */ |
||
46 | public function getIpList() |
||
47 | { |
||
48 | return $this->model->all(); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @param $array |
||
53 | * @return bool |
||
54 | */ |
||
55 | public function saveIp($array) |
||
56 | { |
||
57 | $result = IpList::create($array); |
||
58 | if (!$result){ |
||
59 | return false; |
||
60 | } |
||
61 | |||
62 | return true; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @param $ipAddress |
||
67 | * @return bool |
||
68 | */ |
||
69 | public function deleteIp($ipAddress) |
||
70 | { |
||
71 | $response = false; |
||
72 | $ipList = IpList::where('ip',$ipAddress)->first(); |
||
73 | if ($ipList){ |
||
74 | IpList::where('id',$ipList->id)->delete(); |
||
75 | $response = true; |
||
76 | } |
||
77 | |||
78 | return $response; |
||
79 | } |
||
80 | } |