Completed
Push — master ( f18f3c...2eaba8 )
by ARCANEDEV
09:21
created

SessionActivity::queryRel()   A

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