Completed
Push — master ( d42b43...5ac77a )
by ARCANEDEV
8s
created

RoleRelationships   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 32
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A users() 0 7 1
A permissions() 0 7 1
1
<?php namespace Arcanedev\LaravelAuth\Models\Relationships;
2
3
use Arcanedev\LaravelAuth\Models\Permission;
4
use Arcanedev\LaravelAuth\Models\User;
5
6
/**
7
 * Trait     RoleRelationships
8
 *
9
 * @package  Arcanedev\LaravelAuth\Traits
10
 * @author   ARCANEDEV <[email protected]>
11
 *
12
 * @method  \Illuminate\Database\Eloquent\Relations\BelongsToMany  belongsToMany(string $related, string $table = null, string $foreignKey = null, string $otherKey = null, string $relation = null)
13
 */
14
trait RoleRelationships
15
{
16
    /* ------------------------------------------------------------------------------------------------
17
     |  Relationships
18
     | ------------------------------------------------------------------------------------------------
19
     */
20
    /**
21
     * Role belongs to many users.
22
     *
23
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
24
     */
25
    public function users()
26
    {
27
        $model = config('laravel-auth.users.model', User::class);
28
29
        return $this->belongsToMany($model, 'role_user', 'role_id', 'user_id')
30
                    ->withTimestamps();
31
    }
32
33
    /**
34
     * Role belongs to many permissions.
35
     *
36
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
37
     */
38
    public function permissions()
39
    {
40
        $model = config('laravel-auth.permissions.model', Permission::class);
41
42
        return $this->belongsToMany($model, 'permission_role', 'role_id', 'permission_id')
43
                    ->withTimestamps();
44
    }
45
}
46