本文整理汇总了PHP中app\Role::with方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::with方法的具体用法?PHP Role::with怎么用?PHP Role::with使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Role
的用法示例。
在下文中一共展示了Role::with方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
if (\Auth::user()->roles[0]->can('menu-read')) {
$items = $this->menus->with('roles')->where('parent_id', '=', '0')->orderBy('sort_order', 'ASC')->get();
return \View::make('acl::admin.menus.index', ['items' => $items, 'title' => 'list']);
}
return \Redirect::route('admin.menus.index')->withErrors(trans('acl::dashboard.unauthorized_access'));
}
示例2: getAllRoles
/**
* @param string $order_by
* @param string $sort
* @param bool $withPermissions
* @return mixed
*/
public function getAllRoles($order_by = 'id', $sort = 'asc', $withPermissions = false)
{
if ($withPermissions) {
return Role::with('permissions')->orderBy($order_by, $sort)->get();
}
return Role::orderBy($order_by, $sort)->get();
}
示例3: edit
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$this->authorize('roles-edit');
$role = Role::with('permissions')->findOrFail($id);
$permissions = Permission::orderBy('display_name')->get();
return view('roles.edit', compact('permissions', 'role'));
}
示例4: update_role
public function update_role(Request $request)
{
/*
Delete existing role
*/
Role::where('id', $request->role_id_to_remove)->delete();
if ($request->user_id) {
/*
Add new role/user
*/
$role = new Role();
$role->booking_id = $request->booking_id;
$role->role_type_id = $request->role_type_id;
$role->user_id = $request->user_id;
$role->save();
/*
write to changes
*/
$user_name = User::where('id', $request->user_id)->first()->name;
$change = array('booking_id' => $request->booking_id, 'change_type_id' => 1, 'user_id' => Auth::user()->id, 'from' => null, 'to' => $user_name);
Change::create($change);
$newRole = Role::with('role_type', 'user')->where('id', $role->id)->first();
return $newRole;
}
return;
}
示例5: role
public function role()
{
$roles = Role::with('perms')->get();
$perms = Permission::orderBy('name')->get();
$roles_json = $roles->toArray();
$data = compact('roles', 'perms', 'roles_json');
// dd($data);
return view('user.role', $data);
}
示例6: postGiveRolePermissions
/**
* Store given permissions to role.
*
* @param \Illuminate\Http\Request $request
*
* @return void
*/
public function postGiveRolePermissions(Request $request)
{
$this->validate($request, ['role' => 'required', 'permissions' => 'required']);
$role = Role::with('permissions')->whereName($request->role)->first();
$role->permissions()->detach();
foreach ($request->permissions as $permission_name) {
$permission = Permission::whereName($permission_name)->first();
$role->givePermissionTo($permission);
}
Session::flash('flash_message', 'Permission granted!');
return redirect('admin/roles');
}
示例7: postUserRolePermissions
/**
* Store given permissions to role.
*
* @param \Illuminate\Http\Request $request
*
* @return void
*/
public function postUserRolePermissions(Request $request)
{
$this->validate($request, ['role' => 'required', 'permissions' => 'required']);
$role = Role::with('permissions')->whereName($request->role)->first();
$role->permissions()->detach();
foreach ($request->permissions as $permission_name) {
$permission = Permission::whereName($permission_name)->first();
$role->assign($permission);
}
\Session::flash('flash_message', 'Permission granted!');
return \Redirect::route('admin.assign-role-permissions', []);
}
示例8: 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)
{
$validator = Validator::make($request->all(), ['name' => 'required', 'display' => 'required'], ['name.required' => 'Nama Role tidak boleh kosong.', 'display.required' => 'Alias tidak boleh kosong.']);
if ($validator->fails()) {
return redirect()->back()->withErrors($validator)->withInput();
}
$role = Role::with('permissions')->find($id);
$inPermission = $request->get('permissions') != "" ? $request->get('permissions') : [];
$rolePermission = array_column($role->permissions->toArray(), 'id');
if ($role->update($request->all())) {
// for new permissions
$newPermission = array_diff($inPermission, $rolePermission);
if (count($newPermission)) {
$role->addPermission($newPermission);
}
// for delete permissions
$deletePermission = array_diff($rolePermission, $inPermission);
if (count($deletePermission)) {
$role->removePermission($deletePermission);
}
return redirect('/user/role')->with('succcess', 'Sukses ubah role.');
}
return redirect()->back()->withErrors(['failed' => 'Gagal ubah role.']);
}
示例9: getEffectivePermission
public function getEffectivePermission()
{
if ($this->effectivePermission != null) {
return $this->effectivePermission;
} else {
$role = \App\Role::with('permission')->find($this->getRoleId());
if ($role != null) {
$this->effectivePermission = $role->permission;
} else {
$this->effectivePermission = array();
}
return $this->effectivePermission;
}
}
示例10: getStaff
public function getStaff()
{
$staff = [];
$roles = Role::with('users')->where('board_uri', $this->board_uri)->get();
$roles = [];
foreach ($this->roles as $role) {
foreach ($role->users as $user) {
$staff[$user->user_id] = $user;
if (!isset($roles[$user->user_id])) {
$roles[$user->user_id] = [];
}
$roles[$user->user_id][] = $role;
}
}
foreach ($roles as $user_id => $role) {
$staff[$user_id]->setRelation('roles', collect($role));
}
return $staff;
}
示例11: getStaff
public function getStaff()
{
$staff = [];
$roles = Role::with('users')->where('board_uri', $this->board_uri)->get();
foreach ($this->roles as $role) {
foreach ($role->users as $user) {
$staff[$user->user_id] = $user;
}
}
return $staff;
}
示例12: index
public function index()
{
$roles = Role::with('permissions')->get();
return view('admin.roles.index', compact('roles'));
}
示例13: index
/**
* Display a listing of the resource.
*
* @return \Illuminate\View\View
*/
public function index()
{
$users = $this->users->with('roles')->get();
return \View::make('admin.users.index', ['users' => $users, 'title' => 'list']);
}
示例14: index
/**
* Index
*/
public function index()
{
return Role::with('permissions')->get();
}
示例15: getRoles
public function getRoles()
{
return Role::with('users')->get();
}