当前位置: 首页>>代码示例>>PHP>>正文


PHP models\Role类代码示例

本文整理汇总了PHP中app\models\Role的典型用法代码示例。如果您正苦于以下问题:PHP Role类的具体用法?PHP Role怎么用?PHP Role使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Role类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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));
 }
开发者ID:DCgov,项目名称:dc-madison,代码行数:27,代码来源:RbacSeeder.php

示例2: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $adminRole = new Role();
     $adminRole->name = 'admin';
     $adminRole->display_name = 'Admin';
     $adminRole->description = 'Admin for backend';
     $adminRole->is_admin = 1;
     $adminRole->save();
     $userRole = new Role();
     $userRole->name = 'user';
     $userRole->display_name = 'User';
     $userRole->description = 'user for backend';
     $userRole->is_admin = 0;
     $userRole->save();
     $admin = User::where('email', 'viethung097@gmail.com')->first();
     $assRoleAdmin = new AssignedRole();
     $assRoleAdmin->user_id = $admin->id;
     $assRoleAdmin->role_id = $adminRole->id;
     $assRoleAdmin->save();
     $user = User::where('email', 'johnDoe@gmail.com')->first();
     $assRoleUser = new AssignedRole();
     $assRoleUser->user_id = $user->id;
     $assRoleUser->role_id = $userRole->id;
     $assRoleAdmin->save();
 }
开发者ID:viethung09,项目名称:kidblog,代码行数:30,代码来源:RolesTableSeeder.php

示例3: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $role = new Role();
     $role->name = 'Admin';
     $role->slug = str_slug('admin');
     $role->save();
 }
开发者ID:baconfy,项目名称:skeleton,代码行数:12,代码来源:RolesTableSeeder.php

示例4: destroy

 /**
  * Removes the specified user from the specified role.
  *
  * @param int|string $roleId
  * @param int|string $userId
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function destroy($roleId, $userId)
 {
     $this->authorize('admin.roles.users.destroy');
     $role = $this->role->findOrFail($roleId);
     $user = $role->users()->findOrFail($userId);
     // Retrieve the administrators name.
     $adminName = Role::getAdministratorName();
     // Retrieve all administrators.
     $administrators = $this->user->whereHas('roles', function ($query) use($adminName) {
         $query->whereName($adminName);
     })->get();
     $admin = Role::whereName($adminName)->first();
     // We need to verify that if the user is trying to remove all roles on themselves,
     // and they are the only administrator, that we throw an exception notifying them
     // that they can't do that. Though we want to allow the user to remove the
     // administrator role if more than one administrator exists.
     if ($user->hasRole($admin) && $user->id === auth()->user()->id && count($administrators) === 1) {
         flash()->setTimer(null)->error('Error!', "Unable to remove the administrator role from this user. You're the only administrator.");
         return redirect()->route('admin.roles.show', [$roleId]);
     }
     if ($role->users()->detach($user)) {
         flash()->success('Success!', 'Successfully removed user.');
         return redirect()->route('admin.roles.show', [$roleId]);
     }
     flash()->error('Error!', 'There was an issue removing this user. Please try again.');
     return redirect()->route('admin.roles.show', [$roleId]);
 }
开发者ID:stevebauman,项目名称:ithub,代码行数:35,代码来源:RoleUserController.php

示例5: run

 public function run()
 {
     DB::table('roles')->truncate();
     DB::table('role_user')->truncate();
     DB::table('permissions')->truncate();
     DB::table('permission_role')->truncate();
     $admin_role = new Role();
     $admin_role->name = 'admin';
     $admin_role->display_name = 'Administrator';
     $admin_role->description = 'manages everything';
     $admin_role->save();
     $reviewer_role = new Role();
     $reviewer_role->name = 'reviewer';
     $reviewer_role->display_name = 'Reviewer';
     $reviewer_role->description = 'reviews inserted data';
     $reviewer_role->save();
     $inserter_role = new Role();
     $inserter_role->name = 'inserter';
     $inserter_role->display_name = 'Inserter';
     $inserter_role->description = 'inserts data about billboards';
     $inserter_role->save();
     $admin = User::find(1);
     $reviewer = User::find(2);
     $inserters = User::whereNotIn('id', [$admin->id, $reviewer->id])->get();
     $admin->attachRole($admin_role);
     $reviewer->attachRole($reviewer_role);
     foreach ($inserters as $user) {
         $user->attachRole($inserter_role);
     }
 }
开发者ID:sagaciresearch,项目名称:adtracking,代码行数:30,代码来源:RoleTableSeeder.php

示例6: 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';
     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]);
 }
开发者ID:axex,项目名称:kratos,代码行数:35,代码来源:2016_01_25_135943_entrust_setup_tables.php

示例7: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $user_1 = new User();
     $user_1->name = 'tech';
     $user_1->email = 'tech@ordent.co';
     $user_1->password = \Hash::make('tech1234');
     $user_1->phone = '082214250262';
     $user_1->jabatan = 'Technical Administrator';
     $user_1->save();
     $user_2 = new User();
     $user_2->name = 'admin';
     $user_2->email = 'admin@ordent.co';
     $user_2->password = \Hash::make('admin1234');
     $user_2->phone = '082214250262';
     $user_2->jabatan = 'Management Administrator';
     $user_2->save();
     $role_1 = new Role();
     $role_1->name = 'tech';
     $role_1->display_name = 'tech';
     $role_1->description = 'Technical Administration';
     $role_1->save();
     $role_2 = new Role();
     $role_2->name = 'admin';
     $role_2->display_name = 'admin';
     $role_2->description = 'Management Administration';
     $role_2->save();
     $user_1->attachRole($role_1);
     $user_2->attachRole($role_2);
 }
开发者ID:k1m0ch1,项目名称:egor,代码行数:34,代码来源:UsersSeeder.php

示例8: run

 public function run()
 {
     $roles = ['admin', 'user'];
     foreach ($roles as $role) {
         $instance = new Role(['role' => $role]);
         $instance->save();
     }
 }
开发者ID:koanreview,项目名称:Laravel5Starter,代码行数:8,代码来源:RolesSeeder.php

示例9: run

 public function run()
 {
     DB::table('roles')->delete();
     $adminRole = new Role();
     $adminRole->name = 'admin';
     $adminRole->save();
     $user = User::where('name', '=', 'admin')->first();
     $user->attachRole($adminRole);
 }
开发者ID:Zachary-Leung,项目名称:wine_platform,代码行数:9,代码来源:RolesTableSeeder.php

示例10: execute

 /**
  * @param array $data
  * @return bool
  */
 public function execute(array $data)
 {
     if (!$this->isValid($data)) {
         return false;
     }
     $role = new Role();
     $role->name = $data['name'];
     $role->slug = str_slug($data['name']);
     return $role->save();
 }
开发者ID:baconfy,项目名称:skeleton,代码行数:14,代码来源:CreateRole.php

示例11: completeRegistration

 public function completeRegistration($params = array())
 {
     $user = $this->api->user();
     $defaults = array('verification_code' => $verification_code = null, 'app_subdomain' => $app_subdomain = null, 'email_domains' => $email_domains = null, 'name' => $name = null);
     $this->api->validation_factory->extend('email_domains', function ($attribute, $value, $parameters) {
         $email_domains = $this->toArray($value);
         foreach ($email_domains as $domain) {
             if (!filter_var('fakeemail@' . $domain, FILTER_VALIDATE_EMAIL)) {
                 return false;
             }
         }
         return true;
     });
     $rules = array('verification_code' => array('required', 'exists:organizations,verification_code,registration_complete,0'), 'app_subdomain' => array('required', 'alpha_dash', 'unique:organizations'), 'email_domains' => array('sometimes', 'email_domains'));
     $messages = array('app_subdomain.alpha_dash' => 'Please enter a valid subdomain', 'app_subdomain.unique' => 'The requested subdomain is not available', 'email_domains.email_domains' => 'Please enter valid email domains');
     $params = $this->validateParams($defaults, $params, $rules, $messages);
     extract($params);
     /**
      * @var Organization
      */
     $organization = $this->query()->where('verification_code', $verification_code)->where('registration_complete', false)->first();
     $organization->app_subdomain = $app_subdomain;
     if (!empty($name)) {
         $organization->name = $name;
     }
     /**
      * It's possible that during the time when the above unique subdomain validation
      * is run and the time the organization is saved, that someone else claimed the subdomain.
      * In that case, the save() query will fail, so we wrap it in a try/catch.
      */
     try {
         $organization->save();
         $email_domains = $this->toArray($email_domains);
         if (!empty($email_domains)) {
             $saved_email_domains = array();
             foreach ($email_domains as $email_domain) {
                 $saved_email_domains[] = new EmailDomain(array('domain' => trim($email_domain)));
             }
             $organization->emailDomains()->saveMany($saved_email_domains);
         }
         $admin = new Role();
         $admin->name = $organization->roleAdminName();
         $admin->display_name = $organization->roleAdminDisplayName();
         $admin->save();
         $user->attachRole($admin);
         $organization->registration_complete = true;
         $organization->save();
         $this->entity = $organization;
         $this->api->event->fire(new OrganizationRegistrationCompleted($organization));
         return $this->entity();
     } catch (QueryException $e) {
         throw new BadRequestException('The requested subdomain is not available');
     }
 }
开发者ID:shaunpersad,项目名称:reflect-api,代码行数:54,代码来源:OrganizationsResource.php

示例12: store

 /**
  * Adds the specified permission onto the requested roles.
  *
  * @param PermissionRoleRequest $request
  * @param int|string            $permissionId
  *
  * @return array|false
  */
 public function store(PermissionRoleRequest $request, $permissionId)
 {
     $this->authorize('admin.roles.permissions.store');
     $permission = $this->permission->findOrFail($permissionId);
     $roles = $request->input('roles', []);
     if (count($roles) > 0) {
         $roles = $this->role->findMany($roles);
         return $permission->roles()->saveMany($roles);
     }
     return false;
 }
开发者ID:stevebauman,项目名称:administration,代码行数:19,代码来源:PermissionRoleProcessor.php

示例13: addRole

 public static function addRole($name, $label = null, $description = null)
 {
     $role = Role::query()->where('name', $name)->first();
     if (!$role) {
         $role = new Role(['name' => $name]);
     }
     $role->label = $label;
     $role->description = $description;
     $role->save();
     return $role;
 }
开发者ID:liuzhaowei55,项目名称:Moorper,代码行数:11,代码来源:Role.php

示例14: run

 public function run()
 {
     $items = [["Assistant", "C'est un assistant. Il fait des trucs d'assistant."], ["Soigneur", "Un soigneur guéri un athlète à l'aide de sa magie blanche."], ["Accompagnateur", "Un accompagnateur accompagne un athlète pour qu'il ne soit pas seul."]];
     DB::table('roles')->delete();
     foreach ($items as $item) {
         $role = new Role();
         $role->nom = $item[0];
         $role->description = $item[1];
         $role->save();
     }
 }
开发者ID:BenoitDesrosiers,项目名称:GES2015,代码行数:11,代码来源:RolesSeeder.php

示例15: store

 /**
  * Adds the specified permission to the requested roles.
  *
  * @param PermissionRoleRequest $request
  * @param int|string            $permissionId
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function store(PermissionRoleRequest $request, $permissionId)
 {
     $this->authorize('admin.roles.permissions.store');
     $permission = $this->permission->findOrFail($permissionId);
     $roles = $request->input('roles', []);
     if (count($roles) > 0) {
         $roles = $this->role->findMany($roles);
         $permission->roles()->saveMany($roles);
         flash()->success('Success!', 'Successfully added roles.');
         return redirect()->route('admin.permissions.show', [$permissionId]);
     }
     flash()->error('Error!', "You didn't select any roles!");
     return redirect()->route('admin.permissions.show', [$permissionId]);
 }
开发者ID:stevebauman,项目名称:ithub,代码行数:22,代码来源:PermissionRoleController.php


注:本文中的app\models\Role类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。