本文整理汇总了PHP中app\Member::whereHas方法的典型用法代码示例。如果您正苦于以下问题:PHP Member::whereHas方法的具体用法?PHP Member::whereHas怎么用?PHP Member::whereHas使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Member
的用法示例。
在下文中一共展示了Member::whereHas方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index(Request $request)
{
$queryParameters = array_filter($request->only(['first_name', 'last_name', 'email', 'group']));
$members = Member::with('externalProfiles');
if (array_key_exists('group', $queryParameters)) {
$groupId = $queryParameters['group'];
unset($queryParameters['group']);
$members = Member::whereHas('groups', function ($query) use($groupId) {
$query->where('group_id', $groupId);
});
}
$members->where($queryParameters);
return response()->json($members->paginate());
}
示例2: getToken
public function getToken(Request $request)
{
$this->validate($request, ['id' => 'required', 'provider' => 'required', 'secret' => 'required']);
$queryParameters = $request->only(['id', 'provider', 'secret']);
$id = $queryParameters['id'];
$provider = $queryParameters['provider'];
$secret = $queryParameters['secret'];
if (!in_array($secret, config('auth.secrets'))) {
return new JsonResponse(['error' => 'invalid secret'], Response::HTTP_FORBIDDEN);
}
$member = Member::whereHas('externalProfiles', function ($query) use($id, $provider) {
$query->where('identifier', $id);
$query->where('provider', $provider);
});
try {
$member = $member->firstOrFail();
$token = JWTAuth::fromUser($member, ['level' => config('auth.levels.low'), 'member' => $member]);
return response()->json(['token' => $token]);
} catch (ModelNotFoundException $e) {
return new JsonResponse(['error' => 'not found'], Response::HTTP_NOT_FOUND);
}
}