K
K
Konstantin Malyarov2017-08-06 00:21:24
Laravel
Konstantin Malyarov, 2017-08-06 00:21:24

How to get user->role->permissions?

There are tables.
Simple tables:
user
role
premission
Related:
user_role
premission_role
User.php

public function roles ()
    {
        return $this->belongsToMany(Role::class );
    }

Role.php
public function permissions ()
    {
        return $this->belongsToMany(Permission::class );
    }

HomeController.php
public function index()
    {
        $roles = User::find(Auth::id())->roles;
        foreach ($roles as $role){
            $permissions = Role::find($role->id)->permissions;
        }
        return view('home', compact('roles', 'permissions'));
    }

A user has many groups, a group has many permissions. How to get all permissions?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2017-08-06
@Sanasol

https://stackoverflow.com/questions/32297939/how-t...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question