本文整理汇总了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'));
}