Completed
Push — AddActivityLog ( afa80e...195157 )
by D.
45:05 queued 35:04
created

Group::scopeActiveUsers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace SET;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Group extends Model
8
{
9
    protected $table = 'groups';
10
    public $timestamps = true;
11
12
    protected $fillable = ['name', 'closed_area'];
13
14
    protected $casts = ['closed_area' => 'boolean'];
15
16
    public function users()
17
    {
18
        return $this->belongsToMany('SET\User')->withPivot('access');
19
    }
20
21
    public function trainings()
22
    {
23
        return $this->belongsToMany('SET\Training');
24
    }
25
26
    public function duties()
27
    {
28
        return $this->belongsToMany('SET\Duty');
29
    }
30
31
    public function dutySwap()
32
    {
33
        return $this->morphMany('SET\DutySwap', 'imageable');
34
    }
35
36
    /**
37
     * Allows you to get only active users.
38
     *
39
     * @param $query
40
     *
41
     * @return mixed
42
     */
43
    public function scopeActiveUsers($query)
44
    {
45
        return $query->whereHas('users', function ($q) {
46
            $q->where('status', 'active');
47
        });
48
    }
49
}
50