Skip to content

Commit

Permalink
Merge pull request #229 from ralbear/patch-1
Browse files Browse the repository at this point in the history
Create teams function and update doc
  • Loading branch information
santigarcor committed Jan 10, 2018
2 parents 8744478 + de10c51 commit 2ae4fab
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/configuration/models/user.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ Next, use the ``LaratrustUserTrait`` trait in your existing user models. For exa
...
}
This will enable the relation with ``Role`` and ``Permission``, and add the following methods ``roles()``, ``hasRole($name)``, ``hasPermission($permission)``, ``isAbleTo($permission)``, ``can($permission)``, and ``ability($roles, $permissions, $options)`` within your ``User`` model.
This will enable the relation with ``Role`` and ``Permission``, and add the following methods ``roles()``, ``hasRole($name)``, ``hasPermission($permission)``, ``isAbleTo($permission)``, ``can($permission)``, ``ability($roles, $permissions, $options)``, and ``teams()`` within your ``User`` model.

Do not forget to dump composer autoload::

composer dump-autoload

.. IMPORTANT::
At this point you are ready to go
At this point you are ready to go
18 changes: 18 additions & 0 deletions src/Traits/LaratrustUserTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,24 @@ public function roles()

return $roles;
}

/**
* Many-to-Many relations with Team.
*
* @return \Illuminate\Database\Eloquent\Relations\MorphToMany
*/
public function teams()
{
$teams = $this->morphToMany(
Config::get('laratrust.models.team'),
'user',
Config::get('laratrust.tables.role_user'),
Config::get('laratrust.foreign_keys.user'),
Config::get('laratrust.foreign_keys.team')
);

return $teams;
}

/**
* Many-to-Many relations with Permission.
Expand Down

0 comments on commit 2ae4fab

Please sign in to comment.