Passed
Pull Request — master (#17)
by Stephen
08:18 queued 04:17
created

UserNotification::newFactory()   A

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
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace Sfneal\Users\Models;
4
5
use Database\Factories\UserNotificationFactory;
6
use Illuminate\Database\Eloquent\Builder;
7
use Illuminate\Database\Eloquent\Factories\HasFactory;
8
use Illuminate\Database\Eloquent\Relations\BelongsTo;
9
use Sfneal\Models\Model;
10
use Sfneal\Scopes\CreatedOrderScope;
11
use Sfneal\Users\Builders\UserNotificationBuilder;
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
     *
63
     * @return UserNotificationBuilder
64
     */
65
    public function newEloquentBuilder($query)
66
    {
67
        return new UserNotificationBuilder($query);
68
    }
69
70
    /**
71
     * Custom query Builder.
72
     *
73
     * @return UserNotificationBuilder|Builder
74
     */
75
    public static function query(): UserNotificationBuilder
76
    {
77
        return parent::query();
78
    }
79
80
    /**
81
     * User model this notification subscription belongs to.
82
     *
83
     * @return BelongsTo
84
     */
85
    public function user()
86
    {
87
        return $this->belongsTo(User::class, 'user_id', 'id');
88
    }
89
}
90