https://github.com/appzcoder/laravel-roles
This package is DEPRECATED in favour of laravel-admin
https://github.com/appzcoder/laravel-roles
Last synced: about 1 year ago
JSON representation
This package is DEPRECATED in favour of laravel-admin
- Host: GitHub
- URL: https://github.com/appzcoder/laravel-roles
- Owner: appzcoder
- Created: 2015-07-06T18:24:48.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-08-24T13:15:59.000Z (over 10 years ago)
- Last Synced: 2024-03-25T21:35:07.103Z (about 2 years ago)
- Language: PHP
- Homepage: https://packagist.org/packages/appzcoder/laravel-roles
- Size: 147 KB
- Stars: 6
- Watchers: 4
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Laravel Roles
Laravel 5 User Role Manager
The idea of this package came from laracast [laracasts/Users-and-Roles-in-Laravel](https://github.com/laracasts/Users-and-Roles-in-Laravel) and now it is built for laravel 5.
### Requirements
Laravel >=5.1
PHP >= 5.5.9
## Installation
1. Run
```
composer require "appzcoder/laravel-roles":"dev-master"
```
2. Add service provider into **/config/app.php** file.
```php
'providers' => [
...
Appzcoder\LaravelRoles\LaravelRolesServiceProvider::class,
],
```
4. Publish migrations
```
php artisan vendor:publish
```
4. Run migrate command
```
php artisan migrate
```
5. Include **UserRoles** trait to your **user model** located at **/app/User.php**
```php
use Appzcoder\LaravelRoles\Traits\UserRoles;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract
{
use Authenticatable, CanResetPassword, UserRoles;
```
## Usage
Use the routes as bellow.
```php
Route::get('/roles', function () {
/* Create user if needed
App\User::create([
'name' => 'Sohel Amin',
'email' => 'sohelamincse@gmail.com',
'password' => bcrypt('123456'),
]);
*/
$user = App\User::first();
/* Create roles
$role = new Appzcoder\LaravelRoles\Models\Role;
$role->name = 'admin';
$role->save();
*/
/* Assign and remove role from user
$role = Appzcoder\LaravelRoles\Models\Role::whereName('admin')->first();
$user->assignRole($role);
//$user->removeRole(2);
*/
return $user->roles;
});
Route::get('/admin', ['middleware' => 'role:admin', 'uses' => 'AdminController@index']);
```
##Author