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


PHP Role::firstOrCreate方法代碼示例

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


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

示例1: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $admin = Role::firstOrCreate(['name' => 'admin', 'display_name' => 'Administrator', 'description' => 'Member is an administrator']);
     $member = Role::firstOrCreate(['name' => 'member', 'display_name' => 'Member', 'description' => 'Generic membership role']);
     $mentor = Role::firstOrCreate(['name' => 'mentor', 'display_name' => 'Mentor', 'description' => 'Member is a mentor']);
     $officer = Role::firstOrCreate(['name' => 'officer', 'display_name' => 'Officer', 'description' => 'Member is an officer']);
     if (\App::environment('local')) {
         $member = Member::findOrFail(1);
         $member->attachRole($admin);
     }
 }
開發者ID:rit-sse,項目名稱:api,代碼行數:16,代碼來源:RolesTableSeeder.php

示例2: setOwner

 public function setOwner(User $user)
 {
     $user->forgetPermissions();
     $role = Role::firstOrCreate(['role' => "owner", 'board_uri' => $this->board_uri, 'caste' => NULL, 'inherit_id' => Role::$ROLE_OWNER, 'name' => "Board Owner", 'capcode' => "Board Owner", 'system' => false]);
     return UserRole::create(['user_id' => $user->user_id, 'role_id' => $role->role_id]);
 }
開發者ID:nitogel,項目名稱:infinity-next,代碼行數:6,代碼來源:Board.php

示例3: postRoleCreate

 /**
  * 権限の作成
  */
 public function postRoleCreate(Request $request)
 {
     $role = Role::firstOrCreate($request->only('name'));
     $role->save();
     \Session::flash('flash_message', '権限を作成しました。');
     return redirect()->back();
 }
開發者ID:haruya,項目名稱:admin,代碼行數:10,代碼來源:UsersController.php

示例4: runBoards

 public function runBoards()
 {
     $this->command->comment("\tInserting board owner roles.");
     $boardRole = $this->slugs()[Role::ID_OWNER];
     Board::chunk(50, function ($boards) {
         foreach ($boards as $board) {
             $boardRole = $board->getOwnerRole();
             if (!$boardRole) {
                 $boardRole = Role::getOwnerRoleForBoard($board);
                 $this->command->line("\t/{$board->board_uri}/ has no owner role.");
             }
             $roleModel = Role::firstOrCreate(['role' => $boardRole['role'], 'board_uri' => $board->board_uri, 'caste' => $boardRole['caste']]);
             if ($roleModel->wasRecentlyCreated) {
                 $roleModel->fill(['name' => $boardRole['name'], 'capcode' => $boardRole['capcode'], 'inherit_id' => Role::ID_OWNER, 'system' => false, 'weight' => $boardRole['weight'] + 5])->save();
             }
         }
     });
 }
開發者ID:LulzNews,項目名稱:infinity-next,代碼行數:18,代碼來源:RoleSeeder.php


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