diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..ccb2b73 --- /dev/null +++ b/.env.example @@ -0,0 +1,8 @@ +# Default User Model +ROLES_DEFAULT_USER_MODEL=App\User + +# Roles Database Seeder Settings +ROLES_SEED_DEFAULT_PERMISSIONS=true +ROLES_SEED_DEFAULT_ROLES=true +ROLES_SEED_DEFAULT_RELATIONSHIPS=true +ROLES_SEED_DEFAULT_USERS=false diff --git a/LICENSE b/LICENSE index 9e39446..82378e2 100755 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2017 +Copyright (c) 2017-2019 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. \ No newline at end of file +THE SOFTWARE. diff --git a/readme.md b/readme.md index 9508591..a190098 100755 --- a/readme.md +++ b/readme.md @@ -29,8 +29,10 @@ A Powerful package for handling roles and permissions in Laravel. - [Entity Check](#entity-check) - [Blade Extensions](#blade-extensions) - [Middleware](#middleware) -- [Config File](#config-file) +- [Configuration](#configuration) + - [Environment File](#environment-file) - [More Information](#more-information) +- [File Tree](#file-tree) - [Opening an Issue](#opening-an-issue) - [License](#license) @@ -534,14 +536,185 @@ You can catch these exceptions inside `app/Exceptions/Handler.php` file and do w --- -## Config File -You can change connection for models, slug separator, models path and there is also a handy pretend feature. Have a look at [config file](https://github.com/jeremykenedy/laravel-roles/blob/master/config/roles.php) for more information. +## Configuration +* You can change connection for models, slug separator, models path and there is also a handy pretend feature. +* There are many configurable options which have been extended to be able to configured via `.env` file variables. +* Editing the configuration file directly may not needed becuase of this. +* See config file: [roles.php](https://github.com/jeremykenedy/laravel-roles/blob/master/config/roles.php). + +```php + + null, + + /* + |-------------------------------------------------------------------------- + | Slug Separator + |-------------------------------------------------------------------------- + | + | Here you can change the slug separator. This is very important in matter + | of magic method __call() and also a `Slugable` trait. The default value + | is a dot. + | + */ + + 'separator' => '.', + + /* + |-------------------------------------------------------------------------- + | Models + |-------------------------------------------------------------------------- + | + | If you want, you can replace default models from this package by models + | you created. Have a look at `jeremykenedy\LaravelRoles\Models\Role` model and + | `jeremykenedy\LaravelRoles\Models\Permission` model. + | + */ + + 'models' => [ + 'role' => jeremykenedy\LaravelRoles\Models\Role::class, + 'permission' => jeremykenedy\LaravelRoles\Models\Permission::class, + ], + + /* + |-------------------------------------------------------------------------- + | Roles, Permissions and Allowed "Pretend" + |-------------------------------------------------------------------------- + | + | You can pretend or simulate package behavior no matter what is in your + | database. It is really useful when you are testing you application. + | Set up what will methods hasRole(), hasPermission() and allowed() return. + | + */ + + 'pretend' => [ + + 'enabled' => false, + + 'options' => [ + 'hasRole' => true, + 'hasPermission' => true, + 'allowed' => true, + ], + + ], + + /* + |-------------------------------------------------------------------------- + | Laravel Default User Model + |-------------------------------------------------------------------------- + | + | This is the applications default user model. + | + */ + + 'defaultUserModel' => env('ROLES_DEFAULT_USER_MODEL', config('auth.providers.users.model')), + + /* + |-------------------------------------------------------------------------- + | Default Seeds + |-------------------------------------------------------------------------- + | + | These are the default package seeds. You can seed the package built + | in seeds without having to seed them. These seed directly from + | the package. These are not the published seeds. + | + */ + + 'defaultSeeds' => [ + 'PermissionsTableSeeder' => env('ROLES_SEED_DEFAULT_PERMISSIONS', true), + 'RolesTableSeeder' => env('ROLES_SEED_DEFAULT_ROLES', true), + 'ConnectRelationshipsSeeder' => env('ROLES_SEED_DEFAULT_RELATIONSHIPS', true), + 'UsersTableSeeder' => env('ROLES_SEED_DEFAULT_USERS', false), + ], +]; + + +``` + +### Environment File +``` +# Default User Model +ROLES_DEFAULT_USER_MODEL=App\User + +# Roles Database Seeder Settings +ROLES_SEED_DEFAULT_PERMISSIONS=true +ROLES_SEED_DEFAULT_ROLES=true +ROLES_SEED_DEFAULT_RELATIONSHIPS=true +ROLES_SEED_DEFAULT_USERS=false +``` ## More Information For more information, please have a look at [HasRoleAndPermission](https://github.com/jeremykenedy/laravel-roles/blob/master/src/Contracts/HasRoleAndPermission.php) contract. -## Credit Note -This package is an adaptation of [romanbican/roles](https://github.com/romanbican/roles) and [ultraware/roles](https://github.com/ultraware/roles/). +###File Tree +```bash +├── .env.example +├── .gitignore +├── LICENSE +├── composer.json +├── config +│   └── roles.php +├── readme.md +└── src + ├── Contracts + │   ├── HasRoleAndPermission.php + │   ├── PermissionHasRelations.php + │   └── RoleHasRelations.php + ├── Database + │   ├── Migrations + │   │   ├── 2016_01_15_105324_create_roles_table.php + │   │   ├── 2016_01_15_114412_create_role_user_table.php + │   │   ├── 2016_01_26_115212_create_permissions_table.php + │   │   ├── 2016_01_26_115523_create_permission_role_table.php + │   │   └── 2016_02_09_132439_create_permission_user_table.php + │   └── Seeds + │   ├── DefaultConnectRelationshipsSeeder.php + │   ├── DefaultPermissionsTableSeeder.php + │   ├── DefaultRolesTableSeeder.php + │   ├── DefaultUsersTableSeeder.php + │   └── publish + │   ├── ConnectRelationshipsSeeder.php + │   ├── PermissionsTableSeeder.php + │   ├── RolesTableSeeder.php + │   └── UsersTableSeeder.php + ├── Exceptions + │   ├── AccessDeniedException.php + │   ├── LevelDeniedException.php + │   ├── PermissionDeniedException.php + │   └── RoleDeniedException.php + ├── Middleware + │   ├── VerifyLevel.php + │   ├── VerifyPermission.php + │   └── VerifyRole.php + ├── Models + │   ├── Permission.php + │   └── Role.php + ├── RolesFacade.php + ├── RolesServiceProvider.php + └── Traits + ├── HasRoleAndPermission.php + ├── PermissionHasRelations.php + ├── RoleHasRelations.php + └── Slugable.php +``` + +* Tree command can be installed using brew: `brew install tree` +* File tree generated using command `tree -a -I '.git|node_modules|vendor|storage|tests'` ## Opening an Issue Before opening an issue there are a couple of considerations: @@ -557,5 +730,8 @@ Before opening an issue there are a couple of considerations: * Need some help, I can do my best on Slack: https://opensourcehelpgroup.slack.com * Please be considerate that this is an open source project that I provide to the community for FREE when opening an issue. +## Credit Note +This package is an adaptation of [romanbican/roles](https://github.com/romanbican/roles) and [ultraware/roles](https://github.com/ultraware/roles/). + ## License -This package is free software distributed under the terms of the MIT license. +This package is free software distributed under the terms of the [MIT license](https://opensource.org/licenses/MIT). Enjoy!