Completed
Pull Request — master (#25)
by Karl
05:00
created

User::notifications()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php namespace JobApis\JobsToMail\Models;
2
3
use Illuminate\Database\Eloquent\Model;
4
use Illuminate\Database\Eloquent\SoftDeletes;
5
use Illuminate\Notifications\Notifiable;
6
use Ramsey\Uuid\Uuid;
7
8
class User extends Model
9
{
10
    use Notifiable, SoftDeletes;
11
12
    /**
13
     * Indicates that the IDs are not auto-incrementing.
14
     *
15
     * @var bool
16
     */
17
    public $incrementing = false;
18
19
    /**
20
     * The attributes that are mass assignable.
21
     *
22
     * @var array
23
     */
24
    protected $fillable = [
25
        'email',
26
    ];
27
28
    /**
29
     * Boot function from laravel.
30
     */
31 15
    protected static function boot()
32
    {
33 15
        parent::boot();
34
35 15
        static::creating(function ($model) {
36 2
            $model->{$model->getKeyName()} = Uuid::uuid4();
37 15
        });
38 15
    }
39
40
    /**
41
     * Checks whether the user is premium
42
     *
43
     * @return boolean
44
     */
45 1
    public function isPremium()
46
    {
47 1
        return $this->tier == config('app.user_tiers.premium');
48
    }
49
50
    /**
51
     * Defines the relationship to Search model
52
     *
53
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
54
     */
55 1
    public function searches()
56
    {
57 1
        return $this->hasMany(Search::class);
58
    }
59
60
    /**
61
     * Defines the relationship to Token model
62
     *
63
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
64
     */
65 2
    public function tokens()
66
    {
67 2
        return $this->hasMany(Token::class);
68
    }
69
70
    /**
71
     * Limits query to "confirmed" users
72
     *
73
     * @return \Illuminate\Database\Eloquent\Builder
74
     */
75 2
    public function scopeConfirmed($query)
76
    {
77 2
        return $query->whereNotNull('confirmed_at');
78
    }
79
80
    /**
81
     * Limits query to "unconfirmed" users
82
     *
83
     * @param $query \Illuminate\Database\Eloquent\Builder
84
     *
85
     * @return \Illuminate\Database\Eloquent\Builder
86
     */
87 1
    public function scopeUnconfirmed($query)
88
    {
89 1
        return $query->whereNull('confirmed_at');
90
    }
91
92
    /**
93
     * Get the entity's notifications.
94
     */
95 1
    public function notifications()
96
    {
97
        // Overriding the normal Database Notification model here
98 1
        return $this->morphMany(CustomDatabaseNotification::class, 'notifiable')
99 1
            ->orderBy('created_at', 'desc');
100
    }
101
}
102