Completed
Push — master ( 91f8d9...64265e )
by Mohamed
09:45 queued 06:57
created

RelationTrait::projectUsers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Model\Traits\Role;
13
14
use Illuminate\Database\Eloquent\Relations;
15
use Tinyissue\Model\User;
16
17
/**
18
 * RelationTrait is trait class containing the relationship methods for the Role model.
19
 *
20
 * @author Mohamed Alsharaf <[email protected]>
21
 *
22
 * @method Relations\HasMany       hasMany($related, $foreignKey = null, $localKey = null)
23
 * @method Relations\BelongsToMany belongsToMany($related, $table = null, $foreignKey = null, $otherKey = null, $relation = null)
24
 */
25
trait RelationTrait
26
{
27
    /**
28
     * Role has many users (One-many relationship of User::role).
29
     *
30
     * @return Relations\HasMany
31
     */
32 3
    public function users()
33
    {
34
        return $this
35 3
            ->hasMany('Tinyissue\Model\User', 'role_id', 'id')
36 3
            ->where('deleted', '=', User::NOT_DELETED_USERS)
37 3
            ->orderBy('firstname', 'asc');
38
    }
39
40
    /**
41
     * Role has many users in a project_users.
42
     *
43
     * @return Relations\HasMany
44
     */
45
    public function projectUsers()
46
    {
47
        return $this->hasMany('Tinyissue\Model\Project\User');
48
    }
49
50
    /**
51
     * Role has many role permission.
52
     *
53
     * @return Relations\BelongsToMany
54
     */
55
    public function permissions()
56
    {
57
        return $this->belongsToMany(
58
            '\Tinyissue\Model\Permission',
59
            'roles_permissions',
60
            'role_id',
61
            'permission_id',
62
            'role_id'
63
        );
64
    }
65
}
66