本文整理汇总了PHP中app\Role类的典型用法代码示例。如果您正苦于以下问题:PHP Role类的具体用法?PHP Role怎么用?PHP Role使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Role类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run()
{
DB::table('roles')->delete();
$adminRole = new Role();
$adminRole->name = 'admin';
$adminRole->display_name = 'admin';
$adminRole->description = 'description';
$adminRole->is_admin = 1;
$adminRole->save();
$commentRole = new Role();
$commentRole->name = 'comment';
$commentRole->display_name = 'comment';
$commentRole->description = 'description';
$commentRole->is_admin = 0;
$commentRole->save();
$user = User::where('email', '=', 'admin@admin.com')->first();
$assignedrole = new AssignedRoles();
$assignedrole->user_id = $user->id;
$assignedrole->role_id = $adminRole->id;
$assignedrole->save();
$user = User::where('email', '=', 'user@user.com')->first();
$assignedrole = new AssignedRoles();
$assignedrole->user_id = $user->id;
$assignedrole->role_id = $commentRole->id;
$assignedrole->save();
}
示例2: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
// Creating Roles
$admin = new Role();
$admin->name = 'admin';
$admin->display_name = 'User Administrator';
// optional
$admin->description = 'User is allowed to manage and edit';
// optional
$admin->save();
$moderator = new Role();
$moderator->name = 'moderator';
$moderator->display_name = 'Moderator';
// optional
$moderator->description = 'Moderator is allowed to moderate';
// optional
$moderator->save();
$user = new Role();
$user->name = 'user';
$user->display_name = 'General User';
// optional
$user->description = 'General User is allowed to use facilities of the site';
// optional
$user->save();
// creating an array of roles
$roles = array($admin, $moderator, $user);
// assigning roles to user
$users = User::all();
foreach ($users as $u) {
$u->attachRole($roles[rand(0, 2)]);
}
}
示例3: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$projectManager = new Role();
$projectManager->name = 'project-manager';
$projectManager->display_name = 'Project Manager';
// optional
$projectManager->description = 'User is the manager of a given project';
// optional
$projectManager->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();
$teamLeader = new Role();
$teamLeader->name = 'team-leader';
$teamLeader->display_name = 'Team Leader';
// optional
$teamLeader->description = 'User is the team leader of a given project';
// optional
$teamLeader->save();
$programmer = new Role();
$programmer->name = 'programmer';
$programmer->display_name = 'Programmer';
// optional
$programmer->description = 'User is the team programmer of a given project';
// optional
$programmer->save();
}
示例4: delete
/**
* Delete role
*
* @param Role $role
* @return \Illiminate\Http\RedirectResponse
*/
public function delete(Role $role)
{
if ($role->id !== 1) {
$role->delete();
}
return redirect('admin/roles/list');
}
示例5: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
/**
* Create four roles: admin, moderator, user and guest.
*/
$admin = new Role();
$admin->name = 'admin';
$admin->display_name = 'Administrator';
$admin->description = 'Super User Do';
$admin->save();
$moderator = new Role();
$moderator->name = 'moderator';
$moderator->display_name = 'Moderator';
$moderator->description = 'Kan alle bestellingen zien en gebruikergegevens opvragen.';
$moderator->save();
$user = new Role();
$user->name = 'user';
$user->display_name = 'Gebruiker';
$user->description = 'Standaard gebruiker. Kan bestellingen plaatsen en eigen gegevens inkijken.';
$user->save();
$guest = new Role();
$guest->name = 'guest';
$guest->display_name = 'Gast';
$guest->description = 'Standaard gebruiker. Kan bestellingen plaatsen.';
$guest->save();
/**
* Attach roles to users.
*/
$adminUser = User::where('email', '=', 'sander@dekroon.xyz')->first();
$adminUser->attachRole($admin);
$moderatorUser = User::where('email', '=', 'john@doe.nl')->first();
$moderatorUser->attachRole($moderator);
$normalUser = User::where('email', '=', 'marie@doe.nl')->first();
$normalUser->attachRole($user);
$guestUser = User::where('email', '=', 'gast@gastman.com')->first();
$guestUser->attachRole($guest);
/**
* Create permissions.
*/
$createPage = new Permission();
$createPage->name = 'create-page';
$createPage->display_name = 'Create Pages';
$createPage->description = 'create new pages';
$createPage->save();
$editPage = new Permission();
$editPage->name = 'edit-page';
$editPage->display_name = 'Edit Pages';
$editPage->description = 'edit existing pages';
$editPage->save();
$editUser = new Permission();
$editUser->name = 'edit-user';
$editUser->display_name = 'Edit Users';
$editUser->description = 'edit existing users';
$editUser->save();
/**
* Attach permissions to roles.
*/
$admin->attachPermissions(array($createPage, $editPage, $editUser));
$moderator->attachPermissions(array($createPage, $editPage));
}
示例6: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$admin = new Role();
$admin->name = 'admin';
$admin->display_name = 'Администратор';
// optional
$admin->description = '';
// optional
$admin->save();
DB::table('users')->delete();
$row1 = array_combine(['id', 'name', 'email', 'phone', 'avatar', 'provider', 'provider_id'], $this->items[0]) + ['password' => bcrypt('111111')];
$user1 = User::create($row1);
$row2 = array_combine(['id', 'name', 'email', 'phone', 'avatar', 'provider', 'provider_id'], $this->items[1]) + ['password' => bcrypt('111111')];
$user2 = User::create($row2);
$row3 = array_combine(['id', 'name', 'email', 'phone', 'avatar', 'provider', 'provider_id'], $this->items[2]) + ['password' => bcrypt('zaurzaur')];
$user3 = User::create($row3);
$row4 = array_combine(['id', 'name', 'email', 'phone', 'avatar', 'provider', 'provider_id'], $this->items[3]) + ['password' => bcrypt('16180339887')];
$user4 = User::create($row4);
$row5 = array_combine(['id', 'name', 'email', 'phone', 'avatar', 'provider', 'provider_id'], $this->items[4]) + ['password' => bcrypt('16180339887')];
$user5 = User::create($row5);
$user1->attachRole($admin);
$user3->attachRole($admin);
$user4->attachRole($admin);
$user5->attachRole($admin);
}
示例7: 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]);
}
示例8: store
/**
* Store a newly created resource in storage.
*
* @param Request $request
* @return Response
*/
public function store(RoleFormRequest $request)
{
//Guarda datos del formulario de roles
$role = new Role(array('name' => $request->get('name'), 'display_name' => $request->get('display_name'), 'description' => $request->get('description')));
$role->save();
return redirect('/admin/roles/create')->with('status', 'A new role has been created!');
}
示例9: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//Roles
$userAdmin = new Role();
$userAdmin->name = 'admin';
$userAdmin->display_name = 'Administrator';
$userAdmin->description = 'User is an admin and can edit and manage users';
$userAdmin->save();
$reportsUser = new Role();
$reportsUser->name = 'reports-user';
$reportsUser->display_name = 'Reports User';
$reportsUser->description = 'Reports User can use Note Code Conflicts';
$reportsUser->save();
$csUser = new Role();
$csUser->name = 'cs-user';
$csUser->display_name = 'Customer Service User';
$csUser->description = 'Customer Service User can Upload Notes Import';
$csUser->save();
//Permissions
$userRegistration = new Permission();
$userRegistration->name = 'user-reg';
$userRegistration->display_name = 'User Registration';
$userRegistration->description = 'Create new users admin only';
$userRegistration->save();
$manageUsers = new Permission();
$manageUsers->name = 'manage-users';
$manageUsers->display_name = 'Manage Users';
$manageUsers->description = 'Manage Users - Permissions, etc.';
$manageUsers->save();
$reports = new Permission();
$reports->name = 'reports';
$reports->display_name = 'Reports Section';
$reports->description = 'Access to reports section';
$reports->save();
$admin = new Permission();
$admin->name = 'admin';
$admin->display_name = 'Admin Section';
$admin->description = 'Access to admin section';
$admin->save();
$dispositions = new Permission();
$dispositions->name = 'dispositions';
$dispositions->display_name = 'Disposition Uploads';
$dispositions->description = 'Access to Disposition Uploads';
$dispositions->save();
$notesImport = new Permission();
$notesImport->name = 'notes-import';
$notesImport->display_name = 'Upload Notes Import';
$notesImport->description = 'Access to upload notes import';
$notesImport->save();
$noteConflicts = new Permission();
$noteConflicts->name = 'note-conflicts';
$noteConflicts->display_name = 'Note Code Conflicts';
$noteConflicts->description = 'Access to Node Code Conflicts';
$noteConflicts->save();
$batchRefund = new Permission();
$batchRefund->name = 'batch-refund';
$batchRefund->display_name = 'Batch Refunds';
$batchRefund->description = 'Access to Batch Refunds';
$batchRefund->save();
}
示例10: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('users')->insert(array(['id' => 1, 'name' => 'Admin', 'email' => 'admin@website.com', 'password' => Hash::make('admin'), 'created_at' => new DateTime(), 'updated_at' => new DateTime()], ['id' => 2, 'name' => 'Member', 'email' => 'member@website.com', 'password' => Hash::make('member'), 'created_at' => new DateTime(), 'updated_at' => new DateTime()]));
$admin = new Role();
$admin->name = 'admin';
$admin->display_name = 'User Administrator';
$admin->description = 'User is allowed to manage and edit other users';
$admin->save();
$member = new Role();
$member->name = 'member';
$member->display_name = 'Member';
$member->description = 'User is a member';
$member->save();
$user = User::where('name', '=', 'Admin')->first();
$user->attachRole($admin);
$user = User::where('name', '=', 'Member')->first();
$user->attachRole($member);
$addLocal = new Permission();
$addLocal->name = 'add-local';
$addLocal->display_name = 'Add Local Site';
$addLocal->description = 'add new local site';
$addLocal->save();
$viewContent = new Permission();
$viewContent->name = 'view-content';
$viewContent->display_name = 'View Content';
$viewContent->description = 'view content in system';
$viewContent->save();
$admin->attachPermission($addLocal);
$admin->attachPermission($viewContent);
$member->attachPermission($viewContent);
}
示例11: updatePermissions
/**
* Assign permissions to role
*/
public function updatePermissions(Request $request, Role $role)
{
$permissions = $request->checkedPermissions ?: [];
// $permissions = array of submitted permissions OR if all checkboxes were unchecked, make it an empty array
$role->permissions()->sync($permissions);
logThis('Permissions for ' . $role->label . ' changed to ' . $role->permissions()->lists('label'));
return $role->load('permissions');
}
示例12: run
public function run()
{
$this->command->info('Roles data seeded!');
$owner = new Role();
$owner->name = 'owner';
$owner->display_name = 'Owner';
// optional
$owner->description = 'Root';
// optional
$owner->save();
$admin = new Role();
$admin->name = 'admin';
$admin->display_name = 'Administrator';
// optional
$admin->description = 'Administradores';
// optional
$admin->save();
$this->command->info('Roles data attaching to users!');
if ($owner) {
$owner_user = User::where('name', '=', 'owner')->first();
// role attach alias
$owner_user->attachRole($owner);
// parameter can be an Role object, array, or id
$this->command->info('Owner role attached!');
}
if ($admin) {
$admin_user = User::where('name', '=', 'ligacbb')->first();
// role attach alias
$admin_user->attachRole($admin);
// parameter can be an Role object, array, or id
$this->command->info('Admin role attached!');
}
$this->command->info('Creating Permissions!');
$owner_permission = new Permission();
$owner_permission->name = 'owner-permission';
$owner_permission->display_name = 'Full control';
// optional
// Allow a user to...
$owner_permission->description = '';
// optional
$owner_permission->save();
$admin_permission = new Permission();
$admin_permission->name = 'admin-permission';
$admin_permission->display_name = 'Admin permission';
// optional
// Allow a user to...
$admin_permission->description = '';
// optional
$admin_permission->save();
$this->command->info('Attaching Owner Permission!');
$owner->attachPermission($owner_permission);
// equivalent to $admin->perms()->sync(array($owner_permission->id));
$this->command->info('Attaching Admin Permission!');
$admin->attachPermission($admin_permission);
// equivalent to $owner->perms()->sync(array($createPost->id, $editUser->id));
}
示例13: dashboard
public function dashboard(Request $request, User $user, Role $roles, Message $messages)
{
$user = Auth::user();
$user->usersCount = $user->all()->count();
$user->rolesCount = $roles->all()->count();
$user->contactsCount = $user->contacts()->count();
$user->todosCount = $user->todos()->whereDone(0)->count();
$user->messagesCount = $messages->whereViewed(0)->count();
return view('dashboard.index', compact('user'));
}
示例14: handle
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
foreach ($this->roles as $role) {
$roleModel = new Role();
$roleModel->name = $role['name'];
$roleModel->level = $role['level'];
$roleModel->save();
}
$this->info('User roles generated with success');
}
示例15: checkByAjax
public function checkByAjax()
{
$nameRole = Input::get('newRoleName');
$model = new Role();
if ($model->where('name', $nameRole)->count() > 0) {
return 0;
} else {
return 1;
}
}