本文整理汇总了PHP中app\Group::whereHas方法的典型用法代码示例。如果您正苦于以下问题:PHP Group::whereHas方法的具体用法?PHP Group::whereHas怎么用?PHP Group::whereHas使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Group
的用法示例。
在下文中一共展示了Group::whereHas方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAssignedGroupsToProject
public function getAssignedGroupsToProject($projectId)
{
$groups = Group::whereHas('projects', function ($q) use($projectId) {
$q->where('project_id', $projectId);
})->paginate(5);
return $groups;
}
示例2: redirect
if (Auth::check()) {
Auth::user()->delete();
}
return redirect('/');
});
// Manage Groups
/**
* GET /groups
* Display existing groups for authenticated user
*
* Present form for creating new group
*/
Route::get('/groups', function () {
if (Auth::check()) {
$groups = Group::whereHas('users', function ($q) {
$q->where('id', '=', Auth::id());
})->get();
return view('groups', ['groups' => $groups]);
} else {
return redirect('/');
}
});
/**
* POST /groups
* Create a new group and add authenticated user to it
*/
Route::post('/groups', function (Request $request) {
if (Auth::check()) {
$v = Validator::make($request->all(), ['name' => 'required|max:255']);
if ($v->fails()) {
return redirect()->back()->withInput()->withErrors($v);