本文整理汇总了PHP中app\Role::perms方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::perms方法的具体用法?PHP Role::perms怎么用?PHP Role::perms使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Role
的用法示例。
在下文中一共展示了Role::perms方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postCreate
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function postCreate(Request $request)
{
// Declare the rules for the form validation
$rules = array('name' => 'required|unique:roles', 'display_name' => 'required|unique:roles');
// Validate the inputs
$validator = Validator::make($request->all(), $rules, ['name.required' => 'A name is required.', 'name.unique' => 'Please use a different name.', 'display_name.required' => 'A display name is required', 'display_name.unique' => 'Please use a different display name.']);
// Check if the form validates with success
if ($validator->passes()) {
// Get the inputs, with some exceptions
$inputs = $request->except('csrf_token');
$this->role->name = $request->input('name');
$this->role->display_name = $request->input('display_name');
$this->role->is_protected = $request->has('is_protected') ? 1 : 0;
$this->role->is_superuser = $request->has('is_superuser') ? 1 : 0;
$this->role->save();
// Save permissions
$this->role->perms()->sync($this->permission->preparePermissionsForSave($inputs['permissions']));
// Was the role created?
if ($this->role->id) {
// Redirect to the new role page
Flash::success('Created role');
return redirect('admin/roles/' . $this->role->id . '/edit');
}
// Redirect to the new role page
Flash::error('Could not create role');
return redirect('admin/roles/create');
}
// Form validation failed
return redirect('admin/roles/create')->withInput()->withErrors($validator);
}
示例2: up
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// Inserts the Permissions
Permission::insert($this->permissions);
// Creates a root admin role
$rootadmin = new Role();
$rootadmin->name = "rootadmin";
$rootadmin->display_name = "Root Admin";
$rootadmin->description = "Has Permissions to do everything in the WebPanel";
$rootadmin->save();
//Get all permissions
$ids = Permission::lists('id')->all();
//Sync them to the rootadmin
$rootadmin->perms()->sync($ids);
//Creates an admin user
$admin = new User();
$admin->name = 'admin';
$admin->email = 'admin@admin.com';
$admin->password = bcrypt('password');
$admin->save();
$admin->roles()->sync(array($rootadmin->id));
}
开发者ID:brucewu16899,项目名称:WebPanel-Core,代码行数:27,代码来源:2015_05_20_000000_webpanel_add_permissions_roles.php
示例3: run
public function run()
{
/* Create administrator role */
$admin = new Role();
$admin->name = 'Administrator';
$admin->save();
/* Create officer role */
$officer = new Role();
$officer->name = 'Officer';
$officer->save();
/* Create member role */
$member = new Role();
$member->name = 'Member';
$member->save();
/* Permissions */
/* Default permission for board members */
$manageSystem = new Permission();
$manageSystem->name = 'manage_system';
$manageSystem->display_name = 'Manage System';
$manageSystem->save();
/* Apply permissions */
$admin->perms()->sync(array($manageSystem->id));
$officer->perms()->sync(array($manageSystem->id));
}
示例4: setupFounderAndBaseRolesPermission
/**
* Initialize the user group
*
*/
public function setupFounderAndBaseRolesPermission()
{
//Create Roles
$founder = new Role();
$founder->name = 'Founder';
$founder->save();
$admin = new Role();
$admin->name = 'Admin';
$admin->save();
//Create User
$user = new User();
$user->name = 'muzhuang';
$user->email = 'admin@admin.com';
$user->password = Hash::make('secret');
if (!$user->save()) {
Log::info('Unabel to create user ' . $user->username, (array) $user->errors());
} else {
Log::info('Create user "' . $user->username . '" <' . $user->email . '>');
}
//Attach Roles to user
$user->roles()->attach($founder->id);
//Create Permissions
$manageUsers = new Permission();
$manageUsers->name = 'admin.user';
$manageUsers->display_name = 'Manage Users';
$manageUsers->save();
// Assign Permission to Role
$founder->perms()->sync([$manageUsers->id]);
$admin->perms()->sync([$manageUsers->id]);
}
示例5: remove_permissions_from_role
private function remove_permissions_from_role(Role $role)
{
$role->perms()->sync(array());
}
示例6: currentPerms
/**
* Get list current permission of Role
* @var Role $role
* @return array
*/
public function currentPerms(Role $role)
{
$perms = $role->perms()->lists('id');
return $perms->toArray();
}
示例7: SyncPermissions
/**
* Sync the Server List
*
* @param Role $role
* @param array $permissions
*/
private function SyncPermissions(Role $role, $permissions = array())
{
if ($permissions == null) {
$permissions = array();
}
$role->perms()->sync($permissions);
}
示例8: edit
/**
* Show the form for editing the specified resource.
*
* @param App\Role $role
* @return Response
*/
public function edit($role)
{
$current_permissions = array_pluck($role->perms()->get(['permissions.id'])->toArray(), 'id');
return view('templates.' . \Config::get('webpanel.template') . 'webpanel.panel.roles.edit', compact('role', 'current_permissions'));
}