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

RoleRelationships::permissions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
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