// in User model:
<?php
namespace App;
use IlluminateDatabaseEloquentModel;
class User extends Model
{
/**
* The roles that belong to the user.
*/
public function roles()
{
return $this->belongsToMany('AppRole');
}
}
// in Role model:
<?php
namespace App;
use IlluminateDatabaseEloquentModel;
class Role extends Model
{
/**
* The users that belong to the role.
*/
public function users()
{
return $this->belongsToMany('AppUser')->using('AppUserRole');
}
}