EntityLock::user()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 8
ccs 0
cts 8
cp 0
crap 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/*
3
 * This file is part of the Laravel Platfourm package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Longman\Platfourm\Database\Eloquent\EntityLock;
12
13
use Longman\Platfourm\Database\Eloquent\Model;
14
use Longman\Platfourm\User\Models\Eloquent\User;
15
16
class EntityLock extends Model
17
{
18
19
    public $timestamps = false;
20
21
    /**
22
     * The database table used by the model.
23
     *
24
     * @var string
25
     */
26
    protected $table = 'entity_locks';
27
28
    /**
29
     * The attributes that are mass assignable.
30
     *
31
     * @var array
32
     */
33
    protected $fillable = [
34
        'entity_type', 'entity_id', 'locked_at', 'locked_by'
35
    ];
36
37
    protected $dates = ['locked_at'];
38
39
40
    public static function boot()
41
    {
42
        static::creating(function ($model) {
43
            $model->locked_at = $model->freshTimestamp();
44
        });
45
    }
46
47
    /**
48
     * Polymorphic relationship. Name of the relationship should be
49
     * the same as the prefix for the *_id/*_type fields.
50
     */
51
    public function entity()
52
    {
53
        return $this->morphTo();
54
    }
55
56
57
    public function user()
58
    {
59
        $model = User::class;
60
        if (class_exists(\App\Models\User::class)) {
61
            $model = \App\Models\User::class;
62
        }
63
        return $this->belongsTo($model, 'locked_by');
64
    }
65
66
}
67