UserNotification::query()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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