當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。