本文整理匯總了PHP中app\models\Role::whereHas方法的典型用法代碼示例。如果您正苦於以下問題:PHP Role::whereHas方法的具體用法?PHP Role::whereHas怎麽用?PHP Role::whereHas使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app\models\Role
的用法示例。
在下文中一共展示了Role::whereHas方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: show
public function show($id)
{
if (Auth::user()->can('read-group')) {
$data['group'] = Group::find($id);
$data['title'] = "Group \"" . $data['group']->display_name . "\"";
$roles = Role::get();
$roles_in_group = Role::whereHas('groups', function ($q) use($id) {
$q->where('groups.id', $id);
})->get();
$counter = 0;
foreach ($roles as $role) {
$is_in_group = false;
foreach ($roles_in_group as $role_in_group) {
if ($role->id == $role_in_group->id) {
$is_in_group = true;
}
}
$data['roles'][$counter] = $role;
$data['roles'][$counter]['is_in_group'] = $is_in_group;
$counter++;
}
$data['menu_actions'] = [Form::editItem(route('groups.edit', $id), 'Edit This Group', Auth::user()->can('update-group'))];
return view('groups/show', $data);
} else {
return redirect()->back()->withErrors(['Access denied to groups show page']);
}
}