forked from syntaxlexx/laratrust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
50 changed files
with
1,655 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Introduction | ||
|
||
Laratrust is a Laravel package that lets you handle very easily roles and permissions inside your application. All of this through a very simple configuration process and API. | ||
|
||
Here you can see some examples: | ||
|
||
```php | ||
$adminRole = Role::where('name', 'admin')->first(); | ||
$editUserPermission = Permission::where('name', 'edit-user')->first(); | ||
$user = User::find(1); | ||
|
||
$user->attachRole($adminRole); | ||
// Or | ||
$user->attachRole('admin'); | ||
|
||
$user->attachPermission($editUserPermission); | ||
// Or | ||
$user->attachPermission('edit-user'); | ||
``` | ||
|
||
You can also check if a user has some permissions or roles: | ||
|
||
```php | ||
$user->isAbleTo('edit-user'); | ||
|
||
$user->hasRole('admin'); | ||
$user->isA('guide'); | ||
$user->isAn('admin'); | ||
``` | ||
|
||
It also supports teams, multiple users, objects ownerships, it has a simple admin panel and it is compatible with Laravel's policies and gates system. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Contributing | ||
|
||
We use StyleCI so there is no problem with the styling in your pull requests. | ||
|
||
Please report any issue you find in the package or in the docs. | ||
|
||
Pull requests are welcome. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Installation | ||
|
||
1. You can install the package using composer: | ||
```bash | ||
composer require santigarcor/laratrust | ||
``` | ||
|
||
2. Publish the configuration file: | ||
|
||
```bash | ||
php artisan vendor:publish --tag="laratrust" | ||
``` | ||
::: warning | ||
If this command did not publish any files, chances are, the Laratrust service provider hasn't been registered. Try clearing your configuration cache | ||
```bash | ||
php artisan config:clear | ||
``` | ||
::: | ||
|
||
3. Run the setup command: | ||
|
||
::: tip IMPORTANT | ||
**Before running the command go to your* `config/laratrust.php` *file and change the values according to your needs.** | ||
::: | ||
|
||
```bash | ||
php artisan laratrust:setup | ||
``` | ||
|
||
This command will generate the migrations, create the `Role` and `Permission` models (if you are using the teams feature it will also create a `Team` model) and will add the trait to the configured user models. | ||
|
||
4. Dump the autoloader: | ||
```bash | ||
composer dump-autoload | ||
``` | ||
|
||
5. Run the migrations: | ||
```bash | ||
php artisan migrate | ||
``` | ||
|
||
::: tip IMPORTANT | ||
**If you did the steps above you are done with the configuration, if not, please read and follow the whole configuration process** | ||
::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# License | ||
|
||
Laratrust is free software distributed under the terms of the MIT license. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Migrations | ||
|
||
The migration will create five (or six if you use teams feature) tables in your database: | ||
|
||
* `roles` — stores role records. | ||
* `permissions` — stores permission records. | ||
* `teams` — stores teams records (Only if you use the teams feature). | ||
* `role_user` — stores [polymorphic](https://laravel.com/docs/eloquent-relationships#polymorphic-relations) relations between roles and users. | ||
* `permission_role` — stores [many-to-many](https://laravel.com/docs/eloquent-relationships#many-to-many) relations between roles and permissions. | ||
* `permission_user` — stores [polymorphic](https://laravel.com/docs/eloquent-relationships#polymorphic-relations) relations between users and permissions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Permission | ||
|
||
```php | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Laratrust\Models\LaratrustPermission; | ||
|
||
class Permission extends LaratrustPermission | ||
{ | ||
} | ||
``` | ||
|
||
The `Permission` model has the same three attributes as the `Role`: | ||
|
||
* `name` — Unique name for the permission, used for looking up permission information in the application layer. For example: "create-post", "edit-user", "post-payment", "mailing-list-subscribe". | ||
* `display_name` — Human readable name for the permission. Not necessarily unique and optional. For example "Create Posts", "Edit Users", "Post Payments", "Subscribe to mailing list". | ||
* `description` — A more detailed explanation of the Permission. | ||
|
||
In general, it may be helpful to think of the last two attributes in the form of a sentence: "The permission `display_name` allows a user to `description`." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Role | ||
|
||
```php | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Laratrust\Models\LaratrustRole; | ||
|
||
class Role extends LaratrustRole | ||
{ | ||
} | ||
``` | ||
|
||
The `Role` model has three main attributes: | ||
|
||
* `name` — Unique name for the Role, used for looking up role information in the application layer. For example: "admin", "owner", "employee". | ||
* `display_name` — Human readable name for the Role. Not necessarily unique and optional. For example: "User Administrator", "Project Owner", "Widget Co. Employee". | ||
* `description` — A more detailed explanation of what the Role does. Also, optional. | ||
|
||
Both `display_name` and `description` are optional; their fields are nullable in the database. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Team | ||
|
||
::: tip IMPORTANT | ||
Only applies if you are using the teams feature. | ||
::: | ||
|
||
```php | ||
<?php | ||
|
||
namespace App; | ||
|
||
use Laratrust\Models\LaratrustTeam; | ||
|
||
class Team extends LaratrustTeam | ||
{ | ||
} | ||
``` | ||
|
||
The `Team` model has three main attributes: | ||
|
||
* `name` — Unique name for the Team, used for looking up team information in the application layer. For example: "my-team", "my-company". | ||
* `display_name` — Human readable name for the Team. Not necessarily unique and optional. For example: "My Team", "My Company". | ||
* `description` — A more detailed explanation of what the Team does. Also, optional. | ||
|
||
Both `display_name` and `description` are optional; their fields are nullable in the database. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# User | ||
|
||
```php | ||
<?php | ||
|
||
use Laratrust\Traits\LaratrustUserTrait; | ||
|
||
class User extends Model | ||
{ | ||
use LaratrustUserTrait; // add this trait to your user model | ||
|
||
... | ||
} | ||
``` | ||
|
||
This class uses the `LaratrustUserTrait` to enable the relationships with `Role` and `Permission`.It also adds the following methods `roles()`, `hasRole($name)`, `hasPermission($permission)`, `isAbleTo($permission)`, `ability($roles, $permissions, $options)`, and `rolesTeams()` to the model. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Teams Feature | ||
|
||
::: tip NOTE | ||
The teams feature is **optional**, this part covers how to configure it after the installation. | ||
|
||
If you had your `teams.enabled` value set to `true` during the installation and automatic setup, you can skip this part. | ||
::: | ||
|
||
|
||
1. Set the `teams.enabled` value to `true` in your `config/laratrust.php` file. | ||
|
||
2. Run: | ||
```bash | ||
php artisan laratrust:setup-teams | ||
``` | ||
|
||
3. Run: | ||
```bash | ||
php artisan migrate | ||
``` | ||
|
||
Now you can use the teams feature in you code. | ||
|
||
Please refer to the <docs-link to="/usage/teams.html">teams concepts</docs-link> concepts to learn how to use them. |
Oops, something went wrong.