I'm trying to obtain a three level relationship data, but I'm lost about it using laravel 5.1
I'll try to explain my scenario, hope you can help me.
I've got two models called Host
and User
.
This models are grouped by Hostgroup
and Usergroup
models, using a Many To Many relationship.
Then I've got a table called usergroup_hostgroup_permissions
which relation an Usergroup
with a Hostgroup
:
+--------------+----------------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+----------------------+------+-----+---------------------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| usergroup_id | int(10) unsigned | NO | MUL | NULL | |
| hostgroup_id | int(10) unsigned | NO | MUL | NULL | |
| action | enum('allow','deny') | NO | | allow | |
| enabled | tinyint(1) | NO | | 1 | |
+--------------+----------------------+------+-----+---------------------+----------------+
I'd like to obtain a list of users that belongs to an usergroup with a relation in this table with a hostgroup where my host belongs to.
For example:
My host_1 belongs to DEV_servers
.
On usergroup_hostgroup_permissions
table, there's an entry that allows developers
to access to DEV_servers
.
The usergroup developer
has 3 users user_1, user_2 and user_3.
Any hint? Thanks in advance!