Completed
Push — version-4 ( a26cca...5903bf )
by
unknown
02:38
created

NotificationCategory::scopeByName()   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
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 1
b 0
f 1
1
<?php
2
3
namespace Fenos\Notifynder\Models;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Database\Eloquent\Model;
7
8
class NotificationCategory extends Model
9
{
10
    protected $table = 'notification_categories';
11
12
    protected $fillable = ['name', 'text'];
13
14
    public $timestamps = false;
15
16
    public function notifications()
17
    {
18
        $config = app('notifynder.config');
19
        $model = $config->getNotificationModel();
20
21
        return $this->hasMany($model, 'category_id');
22
    }
23
24
    public function categories()
25
    {
26
        return $this->belongsToMany(
27
            NotificationGroup::class,
28
            'notifications_categories_in_groups',
29
            'category_id',
30
            'group_id'
31
        );
32
    }
33
34
    public function scopeByName(Builder $query, $name)
35
    {
36
        return $query->where('name', $name);
37
    }
38
}
39