本文整理匯總了PHP中app\Role::whereId方法的典型用法代碼示例。如果您正苦於以下問題:PHP Role::whereId方法的具體用法?PHP Role::whereId怎麽用?PHP Role::whereId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\Role
的用法示例。
在下文中一共展示了Role::whereId方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: destroy
public function destroy($id)
{
$role = Role::whereId($id)->first();
$role->delete();
alert()->success('...', 'Rôle supprimé !')->autoclose(3500);
return redirect('/entrust/roles');
}
示例2: it_checks_if_a_user_has_at_least_one_out_of_a_collection_of_roles
/** @test */
public function it_checks_if_a_user_has_at_least_one_out_of_a_collection_of_roles()
{
$user = factory(User::class)->create();
$role_1 = factory(Role::class)->create(['name' => 'role1', 'display_name' => 'Role1']);
$role_2 = factory(Role::class)->create(['name' => 'role2', 'display_name' => 'Role2']);
$user->addRole($role_2);
$this->assertTrue($user->hasRole(Role::all()));
$this->assertFalse($user->hasRole(Role::whereId($role_1->id)->get()));
}
示例3: update
public function update($id)
{
$role = Role::whereId($id)->firstOrFail();
$input = Input::all();
$rules = array('name' => 'required', 'display_name' => 'required');
$validator = Validator::make($input, $rules);
if ($validator->fails()) {
return Response::json(['success' => false, 'errors' => $validator->getMessageBag()->toArray()]);
} else {
$role->name = Input::get('name');
$role->display_name = Input::get('display_name');
$role->description = Input::get('description');
$role->save();
return Response::json(['success' => true, 'message' => 'The role has been updated!']);
}
}
示例4: getDefaultRole
public static function getDefaultRole()
{
$defaultRoleId = Option::getValueByKey('default_role_id');
$defaultRole = Role::whereId($defaultRoleId)->first();
if (!$defaultRole) {
throw new SystemException(SystemException::DefaultRoleNotDefined);
}
return $defaultRole;
}
示例5: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
if (\Auth::user()->roles[0]->can('menu-update')) {
$input = $request->all();
$input['url'] = "admin/" . str_plural(Str::lower($input['name'] != 'Dashboard' ? $string = str_replace(" ", "_", $input['name']) : ''));
$menu = $this->menus->findOrFail($id);
$menu->update($input);
$menu->roles()->detach();
foreach ($request->roles as $_id) {
$role = Role::whereId($_id)->first();
$menu->assign($role);
}
\Session::flash('flash_message', 'Menu updated!');
return \Redirect::route('admin.menus.index', [])->withMessage(trans('acl::menu.menus-controller-successfully_updated'));
}
return \Redirect::route('admin.menus.index')->withErrors(trans('acl::dashboard.unauthorized_access'));
}