Q:

Laravel 5.1 users, roles and actions

I am creating an application using Laravel 5.1 with users, roles and actions.
The table setup is like so:
user
id    name
1     John Smith
2     Fred Smith

role
id    name
1     Administrator
2     Customer

role_user
user_id    role_id
1          1
2          1

action
id    name        description                    path
1     dashboard   ability to access dashboard    /admin
2     editAdmin   ability to edit admins         /admin/users/administrators/{id}/edit

action_role
action_id    role_id
1            1
2            1

The user table holds ALL users on the site, including administrators and customers.
The role table holds all the possible roles a user can have.  For example Administrator or Customer.
The role_user table is a pivot table which links role to user.
The action table lists all of the actions possible (i.e. urls or routes) on the app.
The action_role is a pivot table which links action to role.
So to summarise:

Users have roles
Roles have actions
A user can have many roles
A role can have many actions

I want to have a middleware setup which checks on page load if the user has permissions to view the current page.  In order to do this, I need to be able to access a users actions, using a call like this:
$user->roles()->actions();

How do I setup my eloquent relationships to support this kind of call?
UPDATE
My relationships are setup like so in my models:
User
/**
 * The roles that belong to the user.
 *
 * @return Object
 */
public function roles()
{
    return $this->belongsToMany('App\Models\User\Role')->withTimestamps();
}

Role
/**
 * The actions that belong to the role.
 *
 * @return Object
 */
public function actions() 
{
    return $this->belongsToMany('App\Models\User\Action');
}

/**
 * The users that belong to the role.
 *
 * @return Object
 */
public function users()
{
    return $this->belongsToMany('App\Models\User\User');
}

Action
/**
 * The roles that belong to the action.
 *
 * @return Object
 */
public function roles() 
{
    return $this->belongsToMany('App\Models\User\Role');
}

A:

Eloquent does not have a HasManyThrough relationship across 2 pivot tables.

1. You can get the actions by lazy eager loading the roles and actions, then extracting them:
$actions = $user->load('roles.actions')->roles->pluck('actions')->collapse()->unique();

2. You can check the action directly in the database, using a whereHas constraint:
$allowed = $user->roles()->whereHas('actions', function ($query) use ($action) {
    $query->where('name', $action);
})->exists();

