本文整理汇总了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);
}
}
示例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]);
}
示例3: postRoleCreate
/**
* 権限の作成
*/
public function postRoleCreate(Request $request)
{
$role = Role::firstOrCreate($request->only('name'));
$role->save();
\Session::flash('flash_message', '権限を作成しました。');
return redirect()->back();
}
示例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();
}
}
});
}