本文整理汇总了PHP中Illuminate\Support\Facades\Response::apiResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::apiResponse方法的具体用法?PHP Response::apiResponse怎么用?PHP Response::apiResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\Response
的用法示例。
在下文中一共展示了Response::apiResponse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* @param $request
* @param Closure $next
* @param $permission
*
* @return mixed
*/
public function handle($request, Closure $next, $permission)
{
$token = JWTAuth::getToken();
if (!$token) {
return Response::apiResponse(['httpCode' => 400, 'message' => 'Token não encontrado ou inválido.']);
}
try {
$user = $this->auth->authenticate($token);
} catch (TokenExpiredException $e) {
return Response::apiResponse(['httpCode' => 400, 'message' => 'O token de acesso expirou.']);
} catch (JWTException $e) {
return Response::apiResponse(['httpCode' => 400, 'message' => 'Token inválido.']);
}
if (!$user) {
return Response::apiResponse(['httpCode' => 404, 'message' => 'Usuário não encontrado.']);
}
if (!$user->hasRole(explode('|', $permission))) {
return Response::apiResponse(['httpCode' => 401, 'message' => 'Acesso não autorizado.']);
}
$this->events->fire('tymon.jwt.valid', $user);
return $next($request);
}
示例2: destroy
/**
* Remove uma entidade específica.
*
* @param int $id Id da entidade que deve ser removida
*
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
try {
$wasSuccessful = $this->repository->delete($id);
return Response::apiResponse(['data' => $wasSuccessful]);
} catch (\Exception $e) {
return Response::apiResponse(['httpCode' => 400, 'message' => $e->getMessage()]);
}
}