Giter Club home page Giter Club logo

rolesandpermissionsseeder's Introduction

RolesAndPermissionsSeeder

This Seeder class allows you to manage Roles & Permissions for the Laravel Entrust package.

Relationships between users, roles and permissions will automatically be updated when you make changes to the roles & permissions in the seeder class. To use, just add the class to your /database/seeds directory.


Add your Roles and Permissions to the appropriate arrays within the seeder. e.g.

class RolesAndPermissionsSeeder extends Seeder {

	protected $roles = [
	
		'admin' => [
			'display_name'	=> 'Administrator', // optional
			'description'	=> 'administer the website and manage users', // optional
			'permissions' 	=> ['edit_others_posts','can_add_users', 'edit_own_posts'] // optional
		],
		
		'editor' => [
			'permissions' 	=> ['edit_own_posts']
		],
		
		'member' => [] 
	];
	
	protected $permissions = [
		
		'edit_others_posts' => [
			'display_name' => 'Edit Other\'s Posts', // optional
			'description'  => 'edit other users posts', // optional
		],
		
		'can_add_users' => [],
		
		'edit_own_posts' => []
	];

	...

Run the seed class using the cli

php artisan db:seed --class=RolesAndPermissionsSeeder

You'll get the following output..

 
Creating/updating the 'admin' role
-----------------------------------------
  -> Created admin role
  -> Attached 3 permissions to admin role
 
Creating/updating the 'editor' role
-----------------------------------------
  -> Created editor role
  -> Attached 1 permissions to editor role
 
Creating/updating the 'member' role
-----------------------------------------
  -> Created member role
  -> Attached 0 permissions to member role
 
Cleaning up roles & permissions:
--------------------------------
  -> Done

When you update your roles & permissions here, the changes will be reflected in the database after running the seed. User and Permission relationships will be updated.

rolesandpermissionsseeder's People

Contributors

thomasfw avatar thomasyoungson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rolesandpermissionsseeder's Issues

Error when running the seeder

This error appears when running the seed:
F:\xampp\htdocs\proyect\grupo40>php artisan db:seed --class=RolesAndPermissionsSeeder

Creating/updating the 'admin' role

  [Illuminate\Database\QueryException]
  SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'admin__remove' for key 'roles_name_unique' (SQL: update `roles` set `name` = admin__remove, `updated_at` = 2018
  -04-02 18:24:21 where `id` = 2)



  [PDOException]
  SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'admin__remove' for key 'roles_name_unique'.

I copied and pasted your code, included the roles and permissions (admin, editor..)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.