Completed
Pull Request — develop (#38)
by Neil
09:06
created

Notification::scopeLimit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Notification extends Model
8
{
9
10
    /**
11
     * The table associated with the model.
12
     *
13
     * @var string
14
     */
15
    protected $table = 'notifications';
16
17
    /**
18
     * The primary key column name.
19
     *
20
     * @var string
21
     */
22
    protected $primaryKey = 'notifications_id';
23
24
    /**
25
     * Indicates if the model should be timestamped.
26
     *
27
     * @var bool
28
     */
29
    public $timestamps = false;
30
31
    public function scopeUnread($query)
32
    {
33
        return $query->leftJoin('notifications_attribs', 'notifications.notifications_id', '=', 'notifications_attribs.notifications_id')->whereNull('user_id')->orWhere(['key'=>'sticky', 'value'=> 1]);
34
    }
35
36
    public function scopeRead($query, $user_id)
37
    {
38
        return $query->leftJoin('notifications_attribs', 'notifications.notifications_id', '=', 'notifications_attribs.notifications_id')->where('user_id', $user_id)->where(['key'=>'read', 'value'=> 1]);
39
    }
40
41
    public function scopeLimit($query)
42
    {
43
        return $query->select('notifications.*','key');
44
    }
45
46
}
47