VisitorActivity::queryRel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 2
1
<?php namespace Arcanedev\LaravelTracker\Models;
2
3
use Arcanedev\LaravelTracker\Contracts\Models\VisitorActivity as VisitorActivityContract;
4
use Arcanedev\LaravelTracker\Support\BindingManager;
5
6
/**
7
 * Class     VisitorActivity
8
 *
9
 * @package  Arcanedev\LaravelTracker\Models
10
 * @author   ARCANEDEV <[email protected]>
11
 *
12
 * @property  int             id
13
 * @property  int             visitor_id
14
 * @property  int             path_id
15
 * @property  int             query_id
16
 * @property  int             referrer_id
17
 * @property  string          method
18
 * @property  int             route_path_id
19
 * @property  bool            is_ajax
20
 * @property  bool            is_secure
21
 * @property  bool            is_json
22
 * @property  bool            wants_json
23
 * @property  int             error_id
24
 * @property  \Carbon\Carbon  created_at
25
 * @property  \Carbon\Carbon  updated_at
26
 *
27
 * @property  \Arcanedev\LaravelTracker\Models\Visitor  visitor
28
 * @property  \Arcanedev\LaravelTracker\Models\Path     path
29
 * @property  \Arcanedev\LaravelTracker\Models\Query    queryRel
30
 * @property  \Arcanedev\LaravelTracker\Models\Referer  referer
31
 * @property  \Arcanedev\LaravelTracker\Models\Error    error
32
 */
33
class VisitorActivity extends AbstractModel implements VisitorActivityContract
34
{
35
    /* -----------------------------------------------------------------
36
     |  Properties
37
     | -----------------------------------------------------------------
38
     */
39
40
    /**
41
     * The table associated with the model.
42
     *
43
     * @var string
44
     */
45
    protected $table = 'visitor_activities';
46
47
    /**
48
     * The attributes that are mass assignable.
49
     *
50
     * @var array
51
     */
52
    protected $fillable = [
53
        'visitor_id',
54
        'path_id',
55
        'query_id',
56
        'referrer_id',
57
        'method',
58
        'route_path_id',
59
        'is_ajax',
60
        'is_secure',
61
        'is_json',
62
        'wants_json',
63
        'error_id',
64
    ];
65
66
    /**
67
     * The attributes that should be cast to native types.
68
     *
69
     * @var array
70
     */
71
    protected $casts = [
72
        'id'            => 'integer',
73
        'visitor_id'    => 'integer',
74
        'path_id'       => 'integer',
75
        'query_id'      => 'integer',
76
        'referrer_id'   => 'integer',
77
        'route_path_id' => 'integer',
78
        'is_ajax'       => 'boolean',
79
        'is_secure'     => 'boolean',
80
        'is_json'       => 'boolean',
81
        'wants_json'    => 'boolean',
82
        'error_id'      => 'integer',
83
    ];
84
85
    /* -----------------------------------------------------------------
86
     |  Relationships
87
     | -----------------------------------------------------------------
88
     */
89
90
    /**
91
     * Visitor relationship.
92
     *
93
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
94
     */
95
    public function visitor()
96
    {
97
        return $this->belongsTo(
98
            $this->getModelClass(BindingManager::MODEL_VISITOR, Visitor::class)
99
        );
100
    }
101
102
    /**
103
     * Path relationship.
104
     *
105
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
106
     */
107
    public function path()
108
    {
109
        return $this->belongsTo(
110
            $this->getModelClass(BindingManager::MODEL_PATH, Path::class)
111
        );
112
    }
113
114
    /**
115
     * Query relationship.
116
     *
117
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
118
     */
119
    public function queryRel()
120
    {
121
        return $this->belongsTo(
122
            $this->getModelClass(BindingManager::MODEL_QUERY, Query::class)
123
        );
124
    }
125
126
    /**
127
     * Referrer relationship.
128
     *
129
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
130
     */
131
    public function referrer()
132
    {
133
        return $this->belongsTo(
134
            $this->getModelClass(BindingManager::MODEL_REFERER, Referer::class)
135
        );
136
    }
137
138
    /**
139
     * Error relationship.
140
     *
141
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
142
     */
143
    public function error()
144
    {
145
        return $this->belongsTo(
146
            $this->getModelClass(BindingManager::MODEL_ERROR, Error::class)
147
        );
148
    }
149
150
    /* -----------------------------------------------------------------
151
     |  Check Methods
152
     | -----------------------------------------------------------------
153
     */
154
155
    /**
156
     * Check if the referer exists.
157
     *
158
     * @return bool
159
     */
160
    public function hasReferer()
161
    {
162
        return ! is_null($this->referer);
163
    }
164
}
165