Geoip::requests()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Statistics\Models;
6
7
use Illuminate\Database\Eloquent\Model;
8
use Rinvex\Cacheable\CacheableEloquent;
9
use Rinvex\Support\Traits\ValidatingTrait;
10
use Illuminate\Database\Eloquent\Relations\HasMany;
11
12
class Geoip extends Model
13
{
14
    use ValidatingTrait;
15
    use CacheableEloquent;
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    protected $fillable = [
21
        'client_ip',
22
        'latitude',
23
        'longitude',
24
        'country_code',
25
        'client_ips',
26
        'is_from_trusted_proxy',
27
        'division_code',
28
        'postal_code',
29
        'timezone',
30
        'city',
31
    ];
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    protected $casts = [
37
        'client_ip' => 'string',
38
        'latitude' => 'string',
39
        'longitude' => 'string',
40
        'country_code' => 'string',
41
        'client_ips' => 'json',
42
        'is_from_trusted_proxy' => 'boolean',
43
        'division_code' => 'string',
44
        'postal_code' => 'string',
45
        'timezone' => 'string',
46
        'city' => 'string',
47
    ];
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public $timestamps = false;
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    protected $observables = [
58
        'validating',
59
        'validated',
60
    ];
61
62
    /**
63
     * The default rules that the model will validate against.
64
     *
65
     * @var array
66
     */
67
    protected $rules = [
68
        'client_ip' => 'required|string',
69
        'latitude' => 'required|string',
70
        'longitude' => 'required|string',
71
        'country_code' => 'required|alpha|size:2|country',
72
        'client_ips' => 'nullable|array',
73
        'is_from_trusted_proxy' => 'sometimes|boolean',
74
        'division_code' => 'nullable|string',
75
        'postal_code' => 'nullable|string',
76
        'timezone' => 'nullable|string|max:150|timezone',
77
        'city' => 'nullable|string',
78
    ];
79
80
    /**
81
     * Whether the model should throw a
82
     * ValidationException if it fails validation.
83
     *
84
     * @var bool
85
     */
86
    protected $throwValidationExceptions = true;
87
88
    /**
89
     * Create a new Eloquent model instance.
90
     *
91
     * @param array $attributes
92
     */
93
    public function __construct(array $attributes = [])
94
    {
95
        parent::__construct($attributes);
96
97
        $this->setTable(config('rinvex.statistics.tables.geoips'));
98
    }
99
100
    /**
101
     * The geoip may have many requests.
102
     *
103
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
104
     */
105
    public function requests(): HasMany
106
    {
107
        return $this->hasMany(config('rinvex.statistics.models.request'), 'geoip_id', 'id');
108
    }
109
}
110