Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Notifications;
4
 
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Database\Eloquent\Model;
7
 
8
class DatabaseNotification extends Model
9
{
10
    /**
11
     * The "type" of the primary key ID.
12
     *
13
     * @var string
14
     */
15
    protected $keyType = 'string';
16
 
17
    /**
18
     * Indicates if the IDs are auto-incrementing.
19
     *
20
     * @var bool
21
     */
22
    public $incrementing = false;
23
 
24
    /**
25
     * The table associated with the model.
26
     *
27
     * @var string
28
     */
29
    protected $table = 'notifications';
30
 
31
    /**
32
     * The guarded attributes on the model.
33
     *
34
     * @var array
35
     */
36
    protected $guarded = [];
37
 
38
    /**
39
     * The attributes that should be cast to native types.
40
     *
41
     * @var array
42
     */
43
    protected $casts = [
44
        'data' => 'array',
45
        'read_at' => 'datetime',
46
    ];
47
 
48
    /**
49
     * Get the notifiable entity that the notification belongs to.
50
     *
51
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
52
     */
53
    public function notifiable()
54
    {
55
        return $this->morphTo();
56
    }
57
 
58
    /**
59
     * Mark the notification as read.
60
     *
61
     * @return void
62
     */
63
    public function markAsRead()
64
    {
65
        if (is_null($this->read_at)) {
66
            $this->forceFill(['read_at' => $this->freshTimestamp()])->save();
67
        }
68
    }
69
 
70
    /**
71
     * Mark the notification as unread.
72
     *
73
     * @return void
74
     */
75
    public function markAsUnread()
76
    {
77
        if (! is_null($this->read_at)) {
78
            $this->forceFill(['read_at' => null])->save();
79
        }
80
    }
81
 
82
    /**
83
     * Determine if a notification has been read.
84
     *
85
     * @return bool
86
     */
87
    public function read()
88
    {
89
        return $this->read_at !== null;
90
    }
91
 
92
    /**
93
     * Determine if a notification has not been read.
94
     *
95
     * @return bool
96
     */
97
    public function unread()
98
    {
99
        return $this->read_at === null;
100
    }
101
 
102
    /**
103
     * Scope a query to only include read notifications.
104
     *
105
     * @param  \Illuminate\Database\Eloquent\Builder  $query
106
     * @return \Illuminate\Database\Eloquent\Builder
107
     */
108
    public function scopeRead(Builder $query)
109
    {
110
        return $query->whereNotNull('read_at');
111
    }
112
 
113
    /**
114
     * Scope a query to only include unread notifications.
115
     *
116
     * @param  \Illuminate\Database\Eloquent\Builder  $query
117
     * @return \Illuminate\Database\Eloquent\Builder
118
     */
119
    public function scopeUnread(Builder $query)
120
    {
121
        return $query->whereNull('read_at');
122
    }
123
 
124
    /**
125
     * Create a new database notification collection instance.
126
     *
127
     * @param  array  $models
128
     * @return \Illuminate\Notifications\DatabaseNotificationCollection
129
     */
130
    public function newCollection(array $models = [])
131
    {
132
        return new DatabaseNotificationCollection($models);
133
    }
134
}