本文整理匯總了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);
}
}