Example #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $owner = new Role();
     $owner->name = 'owner';
     $owner->display_name = 'Project Owner';
     // optional
     $owner->description = 'User is the owner of a given project';
     // optional
     $owner->save();
     $admin = new Role();
     $admin->name = 'admin';
     $admin->display_name = 'User Administrator';
     // optional
     $admin->description = 'User is allowed to manage and edit other users';
     // optional
     $admin->save();
     $user = User::whereEMail('*****@*****.**')->first();
     // role attach alias
     $user->attachRole($admin);
     $printReciept = new Permission();
     $printReciept->name = 'print-reciept';
     $printReciept->display_name = 'Create Posts';
     // optional
     // Allow a user to...
     $printReciept->description = 'create new blog posts';
     // optional
     $printReciept->save();
     $editUser = new Permission();
     $editUser->name = 'edit-user';
     $editUser->display_name = 'Edit Users';
     // optional
     // Allow a user to...
     $editUser->description = 'edit existing users';
     // optional
     $editUser->save();
     $admin->attachPermission($createPost);
     // equivalent to $admin->perms()->sync(array($createPost->id));
     $owner->attachPermissions(array($createPost, $editUser));
 }