Device::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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