Agent::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 Agent extends Model
13
{
14
    use ValidatingTrait;
15
    use CacheableEloquent;
16
17
    /**
18
     * {@inheritdoc}
19
     */
20
    protected $fillable = [
21
        'name',
22
        'kind',
23
        'family',
24
        'version',
25
    ];
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    protected $casts = [
31
        'name' => 'string',
32
        'kind' => 'string',
33
        'family' => 'string',
34
        'version' => 'string',
35
    ];
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public $timestamps = false;
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    protected $observables = [
46
        'validating',
47
        'validated',
48
    ];
49
50
    /**
51
     * The default rules that the model will validate against.
52
     *
53
     * @var array
54
     */
55
    protected $rules = [
56
        'name' => 'required|string|strip_tags|max:150',
57
        'kind' => 'required|string|strip_tags|max:150',
58
        'family' => 'required|string|strip_tags|max:150',
59
        'version' => 'nullable|string|strip_tags|max:150',
60
    ];
61
62
    /**
63
     * Whether the model should throw a
64
     * ValidationException if it fails validation.
65
     *
66
     * @var bool
67
     */
68
    protected $throwValidationExceptions = true;
69
70
    /**
71
     * Create a new Eloquent model instance.
72
     *
73
     * @param array $attributes
74
     */
75
    public function __construct(array $attributes = [])
76
    {
77
        parent::__construct($attributes);
78
79
        $this->setTable(config('rinvex.statistics.tables.agents'));
80
    }
81
82
    /**
83
     * The agent may have many requests.
84
     *
85
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
86
     */
87
    public function requests(): HasMany
88
    {
89
        return $this->hasMany(config('rinvex.statistics.models.request'), 'agent_id', 'id');
90
    }
91
}
92