當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Role::firstOrCreate方法代碼示例

本文整理匯總了PHP中app\models\Role::firstOrCreate方法的典型用法代碼示例。如果您正苦於以下問題:PHP Role::firstOrCreate方法的具體用法?PHP Role::firstOrCreate怎麽用?PHP Role::firstOrCreate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\models\Role的用法示例。


在下文中一共展示了Role::firstOrCreate方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: handle

 /**
  * Execute the job.
  *
  * @return Role
  */
 public function handle()
 {
     $label = $this->group->getName();
     $name = str_slug($label);
     // We'll create the role if it doesn't exist already.
     $role = Role::firstOrCreate(compact('name', 'label'));
     // We'll double check that it was successfully retrieved / created.
     if ($role instanceof Role) {
         // Retrieve the members from the AD group.
         $members = $this->group->getMembers();
         foreach ($members as $member) {
             // Import users that may not already be apart of our local DB.
             $user = $this->dispatch(new ImportUser($member));
             // Make sure the user isn't already apart of the role.
             $exists = $role->users()->find($user->id);
             if (!$exists) {
                 // Attach the user to the role if they
                 // aren't currently a member.
                 $role->users()->save($user);
             }
         }
         return $role;
     }
     return false;
 }
開發者ID:stevebauman,項目名稱:ithub,代碼行數:30,代碼來源:ImportGroup.php

示例2: up

 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     $administrator = Role::firstOrCreate(['name' => 'administrator', 'label' => 'Administrator']);
     // Welcome Permissions
     Permission::firstOrCreate(['name' => 'admin.welcome.index', 'label' => 'View Administrator Welcome']);
     // User Permissions
     Permission::firstOrCreate(['name' => 'admin.users.index', 'label' => 'View All Users']);
     Permission::firstOrCreate(['name' => 'admin.users.create', 'label' => 'Create Users']);
     Permission::firstOrCreate(['name' => 'admin.users.edit', 'label' => 'Edit Users']);
     Permission::firstOrCreate(['name' => 'admin.users.show', 'label' => 'View Users']);
     Permission::firstOrCreate(['name' => 'admin.users.destroy', 'label' => 'Delete Users']);
     // Role Permissions
     Permission::firstOrCreate(['name' => 'admin.roles.index', 'label' => 'View All Roles']);
     Permission::firstOrCreate(['name' => 'admin.roles.create', 'label' => 'Create Roles']);
     Permission::firstOrCreate(['name' => 'admin.roles.edit', 'label' => 'Edit Roles']);
     Permission::firstOrCreate(['name' => 'admin.roles.show', 'label' => 'View Roles']);
     Permission::firstOrCreate(['name' => 'admin.roles.destroy', 'label' => 'Delete Roles']);
     // Permission Permissions
     Permission::firstOrCreate(['name' => 'admin.permissions.index', 'label' => 'View All Permissions']);
     Permission::firstOrCreate(['name' => 'admin.permissions.create', 'label' => 'Create Permissions']);
     Permission::firstOrCreate(['name' => 'admin.permissions.edit', 'label' => 'Edit Permissions']);
     Permission::firstOrCreate(['name' => 'admin.permissions.show', 'label' => 'View Permissions']);
     Permission::firstOrCreate(['name' => 'admin.permissions.destroy', 'label' => 'Delete Permissions']);
     // User Permission Permissions
     Permission::firstOrCreate(['name' => 'admin.users.permissions.store', 'label' => 'Add Permissions to Users']);
     Permission::firstOrCreate(['name' => 'admin.users.permissions.destroy', 'label' => 'Remove Permissions from Users']);
     // Role Permission Permissions
     Permission::firstOrCreate(['name' => 'admin.roles.permissions.store', 'label' => 'Add Permissions to Roles']);
     Permission::firstOrCreate(['name' => 'admin.roles.permissions.destroy', 'label' => 'Remove Permissions from Roles']);
     // Role User Permissions
     Permission::firstOrCreate(['name' => 'admin.roles.users.store', 'label' => 'Add Users to Roles']);
     Permission::firstOrCreate(['name' => 'admin.roles.users.destroy', 'label' => 'Remove Users from Roles']);
     $administrator->grant(Permission::all());
 }
開發者ID:stevebauman,項目名稱:administration,代碼行數:39,代碼來源:2014_10_12_300000_seed_roles_and_permissions.php

示例3: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Role::firstOrCreate(['name' => 'hacker']);
     Role::firstOrCreate(['name' => 'exec']);
     Role::firstOrCreate(['name' => 'sponsor']);
     Role::firstOrCreate(['name' => 'sponsor-group-1']);
     Role::firstOrCreate(['name' => 'sponsor-group-2']);
     Role::firstOrCreate(['name' => 'sponsor-group-3']);
 }
開發者ID:BoilerMake,項目名稱:backend,代碼行數:14,代碼來源:RolesSeeder.php

示例4: createRole

 /**
  * Creates a Role and returns it.
  *
  * @param $name
  * @param $display_name
  * @param $description
  * @param bool $enabled
  * @return \App\Models\Role
  */
 protected static function createRole($name, $display_name, $description, $permissions = null, $enabled = true)
 {
     $role = Role::firstOrCreate(['name' => $name, 'display_name' => $display_name, 'description' => $description, 'enabled' => $enabled]);
     if (!is_null($role) && is_array($permissions)) {
         $role->perms()->sync($permissions);
     }
     return $role;
 }
開發者ID:sroutier,項目名稱:l51esk-modules,代碼行數:17,代碼來源:MaintenanceTrait.php


注:本文中的app\models\Role::firstOrCreate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。