TrackAction::newFactory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Sfneal\Tracking\Models;
4
5
use Database\Factories\TrackActionFactory;
6
use Illuminate\Database\Eloquent\Builder;
7
use Illuminate\Database\Eloquent\Factories\HasFactory;
8
use Illuminate\Database\Eloquent\Relations\MorphTo;
9
use Sfneal\Scopes\CreatedOrderScope;
10
use Sfneal\Scopes\IdOrderScope;
11
use Sfneal\Tracking\Builders\TrackActionBuilder;
12
use Sfneal\Tracking\Models\Base\Tracking;
13
14
class TrackAction extends Tracking
15
{
16
    use HasFactory;
17
18
    /**
19
     * The "booting" method of the model.
20
     *
21
     * @return void
22
     */
23
    protected static function boot()
24
    {
25
        parent::boot();
26
        static::addGlobalScope(new CreatedOrderScope());
27
        static::addGlobalScope(new IdOrderScope());
28
    }
29
30
    protected $table = 'track_action';
31
    protected $primaryKey = 'track_action_id';
32
33
    protected $fillable = [
34
        'track_action_id',
35
        'action',
36
        'model_changes',
37
        'trackable_id',
38
        'trackable_type',
39
    ];
40
41
    /**
42
     * The attributes that should be cast to native types.
43
     *
44
     * @var array
45
     */
46
    protected $casts = [
47
        'model_changes' => 'array',
48
        'trackable_id' => 'int',
49
    ];
50
51
    /**
52
     * Create a new factory instance for the model.
53
     *
54
     * @return TrackActionFactory
55
     */
56
    protected static function newFactory(): TrackActionFactory
57
    {
58
        return new TrackActionFactory();
59
    }
60
61
    /**
62
     * Query Builder.
63
     *
64
     * @param $query
65
     * @return TrackActionBuilder
66
     */
67
    public function newEloquentBuilder($query)
68
    {
69
        return new TrackActionBuilder($query);
70
    }
71
72
    /**
73
     * @return TrackActionBuilder|Builder
74
     */
75
    public static function query(): TrackActionBuilder
76
    {
77
        return parent::query();
78
    }
79
80
    /**
81
     * Get the owning trackable model.
82
     *
83
     * @return MorphTo
84
     */
85
    public function trackable(): MorphTo
86
    {
87
        return $this->morphTo();
88
    }
89
}
90