当前位置: 首页>>代码示例>>PHP>>正文


PHP Response::apiResponse方法代码示例

本文整理汇总了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);
 }
开发者ID:lfalmeida,项目名称:lbase,代码行数:29,代码来源:TokenEntrustPermission.php

示例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()]);
     }
 }
开发者ID:lfalmeida,项目名称:lbase,代码行数:16,代码来源:ApiBaseController.php


注:本文中的Illuminate\Support\Facades\Response::apiResponse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。