本文整理汇总了PHP中Role::perms方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::perms方法的具体用法?PHP Role::perms怎么用?PHP Role::perms使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Role
的用法示例。
在下文中一共展示了Role::perms方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
// Declare the rules for the form validation
$rules = array('name' => 'required');
$getPermissions = Input::get('permissions');
// Validate the inputs
$validator = Validator::make(Input::all(), $rules);
// Check if the form validates with success
if ($validator->passes()) {
// Get the inputs, with some exceptions
$inputs = Input::except('csrf_token');
$this->role->name = $inputs['name'];
$this->role->save();
// Save permissions
$perms = $this->permission->get();
if (count($perms)) {
if (isset($getPermissions)) {
$this->role->perms()->sync($this->permission->preparePermissionsForSave($getPermissions));
}
}
// Was the role created?
if ($this->role->id) {
// Redirect to the new role page
return Redirect::to('admin/roles/' . $this->role->id . '/edit')->with('success', Lang::get('admin/roles/messages.create.success'));
}
// Redirect to the new role page
return Redirect::to('admin/roles/create')->with('error', Lang::get('admin/roles/messages.create.error'));
// Redirect to the role create page
return Redirect::to('admin/roles/create')->withInput()->with('error', Lang::get('admin/roles/messages.' . $error));
}
// Form validation failed
return Redirect::to('admin/roles/create')->withInput()->withErrors($validator);
}
示例2: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
// Validate the inputs
$rules = array('name' => 'required|alpha_dash|unique:roles,name', 'description' => 'required');
// Validate the inputs
$validator = Validator::make(Input::all(), $rules);
// Check if the form validates with success
if ($validator->passes()) {
// Get the inputs, with some exceptions
$inputs = Input::except('csrf_token');
$this->role->name = $inputs['name'];
$this->role->description = $inputs['description'];
$this->role->save($rules);
if ($this->role->id) {
// Save permissions
$this->role->perms()->sync($this->permission->preparePermissionsForSave($inputs['permissions']));
// Redirect to the new role page
return Redirect::to('admin/roles/' . $this->role->id . '/edit')->with('success', Lang::get('admin/role/messages.create.success'));
} else {
// Redirect to the role create page
//var_dump($this->role);
return Redirect::to('admin/roles/create')->with('error', Lang::get('admin/role/messages.create.error'));
}
} else {
// Form validation failed
return Redirect::to('admin/roles/create')->withInput()->withErrors($validator);
}
}
示例3: run
public function run()
{
if (file_exists(app_path() . '/config/creds.yml')) {
$creds = yaml_parse_file(app_path() . '/config/creds.yml');
} else {
$creds = array('admin_email' => 'admin@example.com');
}
$admin = new Role();
$admin->name = 'Admin';
$admin->save();
$independent_sponsor = new Role();
$independent_sponsor->name = 'Independent Sponsor';
$independent_sponsor->save();
$permIds = array();
foreach ($this->adminPermissions as $permClass => $data) {
$perm = new Permission();
foreach ($data as $key => $val) {
$perm->{$key} = $val;
}
$perm->save();
$permIds[] = $perm->id;
}
$admin->perms()->sync($permIds);
$user = User::where('email', '=', $creds['admin_email'])->first();
$user->attachRole($admin);
$createDocPerm = new Permission();
$createDocPerm->name = "independent_sponsor_create_doc";
$createDocPerm->display_name = "Independent Sponsoring";
$createDocPerm->save();
$independent_sponsor->perms()->sync(array($createDocPerm->id));
}
示例4: run
public function run()
{
$adminEmail = Config::get('madison.seeder.admin_email');
$admin = new Role();
$admin->name = 'Admin';
$admin->save();
$independent_sponsor = new Role();
$independent_sponsor->name = 'Independent Sponsor';
$independent_sponsor->save();
$permIds = array();
foreach ($this->adminPermissions as $permClass => $data) {
$perm = new Permission();
foreach ($data as $key => $val) {
$perm->{$key} = $val;
}
$perm->save();
$permIds[] = $perm->id;
}
$admin->perms()->sync($permIds);
$user = User::where('email', '=', $adminEmail)->first();
$user->attachRole($admin);
$createDocPerm = new Permission();
$createDocPerm->name = "independent_sponsor_create_doc";
$createDocPerm->display_name = "Independent Sponsoring";
$createDocPerm->save();
$independent_sponsor->perms()->sync(array($createDocPerm->id));
}
示例5: postCreate
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function postCreate()
{
$rules = array('name' => 'required');
$validator = Validator::make(Input::all(), $rules);
if ($validator->passes()) {
$inputs = Input::except('csrf_token');
$this->role->name = $inputs['name'];
$this->role->save();
$this->role->perms()->sync($this->permission->preparePermissionsForSave($inputs['permissions']));
if ($this->role->id) {
return Redirect::to('admin/roles/' . $this->role->id . '/edit')->with('success', Lang::get('admin/roles/messages.create.success'));
}
return Redirect::to('admin/roles/create')->with('error', Lang::get('admin/roles/messages.create.error'));
return Redirect::to('admin/roles/create')->withInput()->with('error', Lang::get('admin/roles/messages.' . $error));
}
return Redirect::to('admin/roles/create')->withInput()->withErrors($validator);
}
示例6: store
/**
* Stores new account
*
* @return Illuminate\Http\Response
*/
public function store()
{
$perms = Input::get('permission');
$role = new Role();
$role->name = Input::get('name');
$role->save();
$role->perms()->sync($perms);
return Redirect::route('roles.index');
}
示例7: run
public function run()
{
$admin = new Role();
$admin->name = 'Admin';
$admin->save();
$managePages = Permission::where('name', '=', 'manage_pages')->first();
$manageUsers = Permission::where('name', '=', 'manage_users')->first();
$manageSermons = Permission::where('name', '=', 'manage_sermons')->first();
$admin->perms()->sync(array($managePages->id, $manageUsers->id, $manageSermons->id));
$member = new Role();
$member->name = 'Member';
$member->save();
}
示例8: postCreate
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function postCreate()
{
$rules = array('name' => 'required');
$validator = Validator::make(Input::all(), $rules);
if ($validator->passes()) {
if (in_array(Input::get('name'), $this->protected_roles)) {
return Api::to(array('error', Lang::get('admin/roles/messages.create.error'))) ?: Redirect::to('admin/roles/create')->with('error', Lang::get('admin/roles/messages.create.error'));
}
// Get the inputs, with some exceptions
$inputs = Input::except('csrf_token');
$this->role->name = $inputs['name'];
$this->role->save();
// Save permissions
$this->role->perms()->sync($this->permission->preparePermissionsForSave($inputs['permissions']));
// Was the role created?
if ($this->role->id) {
return Api::to(array('success', Lang::get('admin/roles/messages.create.success'))) ?: Redirect::to('admin/roles/' . $this->role->id . '/edit')->with('success', Lang::get('admin/roles/messages.create.success'));
} else {
return Api::to(array('error', Lang::get('admin/roles/messages.create.error'))) ?: Redirect::to('admin/roles/create')->withInput()->with('error', Lang::get('admin/roles/messages.create.error'));
}
} else {
return Api::to(array('error', Lang::get('admin/roles/messages.create.error'))) ?: Redirect::to('admin/roles/create')->withInput()->withErrors($validator);
}
}
示例9: run
public function run()
{
// Uncomment the below to wipe the table clean before populating
DB::statement('SET FOREIGN_KEY_CHECKS=0;');
DB::table('roles')->truncate();
$godRole = new Role();
$godRole->name = 'god';
$godRole->save();
$superadminRole = new Role();
$superadminRole->name = 'superadmin';
$superadminRole->save();
$adminRole = new Role();
$adminRole->name = 'admin';
$adminRole->save();
$userRole = new Role();
$userRole->name = 'user';
$userRole->save();
$god = User::where('username', '=', 'admin')->first();
$god->attachRole($godRole);
DB::table('permissions')->truncate();
$manageGods = new Permission();
$manageGods->name = 'manage_gods';
$manageGods->display_name = 'Manage Gods';
$manageGods->save();
$manageSuperadmins = new Permission();
$manageSuperadmins->name = 'manage_superadmins';
$manageSuperadmins->display_name = 'Manage Superadmins';
$manageSuperadmins->save();
$manageAdmins = new Permission();
$manageAdmins->name = 'manage_admins';
$manageAdmins->display_name = 'Manage Admins';
$manageAdmins->save();
$manageUsers = new Permission();
$manageUsers->name = 'manage_users';
$manageUsers->display_name = 'Manage Users';
$manageUsers->save();
$godRole->perms()->sync(array($manageGods->id, $manageSuperadmins->id, $manageAdmins->id, $manageUsers->id));
$superadminRole->perms()->sync(array($manageSuperadmins->id, $manageAdmins->id, $manageUsers->id));
$adminRole->perms()->sync(array($manageAdmins->id, $manageUsers->id));
DB::statement('SET FOREIGN_KEY_CHECKS=1;');
}
示例10: setupFoundorAndBaseRolsPermission
public function setupFoundorAndBaseRolsPermission()
{
// Create Roles
$founder = new Role();
$founder->name = 'Founder';
$founder->save();
$admin = new Role();
$admin->name = 'Admin';
$admin->save();
// Create User
$user = User::create(['github_id' => 324764, 'github_url' => 'https://github.com/summerblue', 'name' => 'summerblue']);
// Attach Roles to user
$user->roles()->attach($founder->id);
// Create Permissions
$manageTopics = new Permission();
$manageTopics->name = 'manage_topics';
$manageTopics->display_name = 'Manage Topics';
$manageTopics->save();
$manageUsers = new Permission();
$manageUsers->name = 'manage_users';
$manageUsers->display_name = 'Manage Users';
$manageUsers->save();
// Assign Permission to Role
$founder->perms()->sync([$manageTopics->id, $manageUsers->id]);
$admin->perms()->sync([$manageTopics->id]);
}
示例11: createRbacRules
public function createRbacRules()
{
$this->destroyRbacRules();
$ownerRole = new Role();
$ownerRole->name = "group_{$this->id}_owner";
$ownerRole->save();
$permissions = $this->getPermissionsArray();
$permIds = array();
$permLookup = array();
foreach ($permissions as $perm) {
$permModel = new Permission();
foreach ($perm as $key => $val) {
$permModel->{$key} = $val;
}
$permModel->save();
$permIds[] = $permModel->id;
switch ($perm['name']) {
case "group_{$this->id}_create_document":
$permLookup['create'] = $permModel->id;
break;
case "group_{$this->id}_edit_document":
$permLookup['edit'] = $permModel->id;
break;
case "group_{$this->id}_delete_document":
$permLookup['delete'] = $permModel->id;
break;
case "group_{$this->id}_manage_document":
$permLookup['manage'] = $permModel->id;
break;
}
}
$ownerRole->perms()->sync($permIds);
$editorRole = new Role();
$editorRole->name = "group_{$this->id}_editor";
$editorRole->save();
$editorRole->perms()->sync(array($permLookup['create'], $permLookup['edit'], $permLookup['manage']));
$staffRole = new Role();
$staffRole->name = "group_{$this->id}_staff";
$staffRole->save();
$users = array(static::ROLE_OWNER => $this->findUsersByRole(static::ROLE_OWNER), static::ROLE_EDITOR => $this->findUsersByRole(static::ROLE_EDITOR), static::ROLE_STAFF => $this->findUsersByRole(static::ROLE_STAFF));
foreach ($users as $role => $userList) {
foreach ($userList as $userObj) {
switch ($role) {
case static::ROLE_OWNER:
$userObj->attachRole($ownerRole);
break;
case static::ROLE_EDITOR:
$userObj->attachRole($editorRole);
break;
case static::ROLE_STAFF:
$userObj->attachRole($staffRole);
break;
}
}
}
}
示例12: updateRole
public function updateRole()
{
$prevURL = Request::header('referer');
if (!Request::isMethod('post')) {
return App::abort(404);
}
if (Input::has('id')) {
try {
$role = Role::findorFail((int) Input::get('id'));
} catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {
return App::abort(404);
}
$create = false;
$message = 'has been updated successful';
} else {
$create = true;
$role = new Role();
$message = 'has been added successful';
}
$role->name = Input::has('name') ? Input::get('name') : '';
$pass = $role->valid();
if ($pass->passes()) {
Permission::generatePermission();
$role->save();
if (Input::has('permission')) {
$arrAssignedPermission = [];
$arrPermission = Input::get('permission');
foreach ($arrPermission as $controller => $permission) {
foreach ($permission as $action => $type) {
$currentPerrmission = Permission::select('id')->where('name', 'like', "%{$controller}_{$action}_%")->where('name', '<>', "{$controller}_{$action}_{$type}")->get();
if (!$currentPerrmission->isEmpty()) {
$arrId = [];
foreach ($currentPerrmission as $id) {
$arrId[] = $id->id;
}
DB::table('permission_role')->where('role_id', $role->id)->whereIn('permission_id', $arrId)->delete();
unset($currentPerrmission, $arrId);
}
if ($type != 'none') {
$permission_id = Permission::where('name', "{$controller}_{$action}_{$type}")->pluck('id');
if (is_null($permission_id)) {
continue;
}
$arrAssignedPermission[] = $permission_id;
}
}
}
if (!empty($arrAssignedPermission)) {
$role->perms()->sync($arrAssignedPermission);
}
Cache::tags('menu', 'frontend')->flush();
Cache::tags('menu', 'backend')->flush();
}
if (Input::has('continue')) {
if ($create) {
$prevURL = URL . '/admin/roles/edit-role/' . $role->id;
}
return Redirect::to($prevURL)->with('flash_success', "<b>{$role->name}</b> {$message}.");
}
return Redirect::to(URL . '/admin/roles')->with(['flash_success' => "{$role->name} {$message}."]);
}
return Redirect::to($prevURL)->with(['flash_error' => $pass->messages()->all()])->withInput();
}
示例13: setupFoundorAndBaseRolsPermission
public function setupFoundorAndBaseRolsPermission()
{
// Create Roles
$founder = new Role();
$founder->name = 'Founder';
$founder->save();
$admin = new Role();
$admin->name = 'Admin';
$admin->save();
// Create User
$user = User::create(['id' => 1, 'username' => 'zhanglei', 'password' => Hash::make('zhanglei'), 'email' => 'fcode520@gmail.com']);
// Attach Roles to user
$user->roles()->attach($founder->id);
// Create Permissions
$manageTopics = new Permission();
$manageTopics->name = 'manage_topics';
$manageTopics->display_name = 'Manage Topics';
$manageTopics->save();
$manageUsers = new Permission();
$manageUsers->name = 'manage_users';
$manageUsers->display_name = 'Manage Users';
$manageUsers->save();
// Assign Permission to Role
$founder->perms()->sync([$manageTopics->id, $manageUsers->id]);
$admin->perms()->sync([$manageTopics->id]);
}
示例14: run
//.........这里部分代码省略.........
$perm->name = 'manage_holiday';
$perm->display_name = 'Manage holidays';
$perm->category = 'Leave';
$perm->save();
$perm = new Permission();
$perm->name = 'view_leave_report';
$perm->display_name = 'View reports';
$perm->category = 'Leave';
$perm->save();
$perm = new Permission();
$perm->name = 'manage_organization';
$perm->display_name = 'manage organization';
$perm->category = 'Organization';
$perm->save();
$perm = new Permission();
$perm->name = 'manage_branch';
$perm->display_name = 'manage branches';
$perm->category = 'Organization';
$perm->save();
$perm = new Permission();
$perm->name = 'manage_group';
$perm->display_name = 'manage groups';
$perm->category = 'Organization';
$perm->save();
$perm = new Permission();
$perm->name = 'manage_organization_settings';
$perm->display_name = 'manage settings';
$perm->category = 'Organization';
$perm->save();
$perm = new Permission();
$perm->name = 'manage_user';
$perm->display_name = 'manage users';
$perm->category = 'System';
$perm->save();
$perm = new Permission();
$perm->name = 'manage_role';
$perm->display_name = 'manage roles';
$perm->category = 'System';
$perm->save();
$perm = new Permission();
$perm->name = 'manage_audit';
$perm->display_name = 'manage audits';
$perm->category = 'System';
$perm->save();
$perms = Permission::all();
$pers = array();
foreach ($perms as $p) {
$pers[] = $p->id;
}
$role = new Role();
$role->name = 'superadmin';
$role->save();
$role->perms()->sync($pers);
$data = array('username' => 'superadmin', 'email' => 'superadmin@lixnet.net', 'password' => 'superadmin', 'password_confirmation' => 'superadmin', 'user_type' => 'admin', 'organization_id' => 1);
$repo = App::make('UserRepository');
$user = $repo->register($data);
$user->attachRole($role);
/*
$perm = new Permission;
$perm->name = 'view_loan_product';
$perm->display_name = 'view loan products';
$perm->category = 'Loanproduct';
$perm->save();
$perm = new Permission;
$perm->name = 'delete_loan_product';
$perm->display_name = 'delete loan products';
$perm->category = 'Loanproduct';
$perm->save();
$perm = new Permission;
$perm->name = 'create_loan_account';
$perm->display_name = 'create loan account';
$perm->category = 'Loanaccount';
$perm->save();
$perm = new Permission;
$perm->name = 'view_loan_account';
$perm->display_name = 'view loan account';
$perm->category = 'Loanaccount';
$perm->save();
$perm = new Permission;
$perm->name = 'approve_loan_account';
$perm->display_name = 'approve loan';
$perm->category = 'Loanaccount';
$perm->save();
$perm = new Permission;
$perm->name = 'disburse_loan';
$perm->display_name = 'disburse loan';
$perm->category = 'Loanaccount';
$perm->save();
$perm = new Permission;
$perm->name = 'view_savings_account';
$perm->display_name = 'view savings account';
$perm->category = 'Savingaccount';
$perm->save();
$perm = new Permission;
$perm->name = 'open_saving_account';
$perm->display_name = 'Open savings account';
$perm->category = 'Savingaccount';
$perm->save();
*/
}
示例15: setupFoundorAndBaseRolsPermission
public function setupFoundorAndBaseRolsPermission()
{
// Create Roles
$founder = new Role();
$founder->name = 'Founder';
$founder->save();
$admin = new Role();
$admin->name = 'Admin';
$admin->save();
// Create User
$user = new User();
$user->username = 'admin';
$user->display_name = 'Admin';
$user->email = 'admin@local.com';
$user->password = 'admin';
$user->password_confirmation = 'admin';
$user->confirmation_code = md5(uniqid(mt_rand(), true));
$user->confirmed = true;
if (!$user->save()) {
Log::info('Unable to create user ' . $user->username, (array) $user->errors());
} else {
Log::info('Created user "' . $user->username . '" <' . $user->email . '>');
}
// Attach Roles to user
$user->roles()->attach($founder->id);
// Create Permissions
$manageContent = new Permission();
$manageContent->name = 'manage_contents';
$manageContent->display_name = 'Manage Content';
$manageContent->save();
$manageUsers = new Permission();
$manageUsers->name = 'manage_users';
$manageUsers->display_name = 'Manage Users';
$manageUsers->save();
// Assign Permission to Role
$founder->perms()->sync([$manageContent->id, $manageUsers->id]);
$admin->perms()->sync([$manageContent->id]);
}