1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace App\Http\Controllers\Traits;
- use App\Servers\MemberLogsServer;
- trait ApiResponseTrait
- {
- /**
- * @param array $data ## 返回数据
- * @param string $msg ## 返回信息 如:auth.failed
- * @param int $code ## 响应编码 1:成功 0:失败
- * @param int $status ## HTTP响应状态 200:请求成功
- * @param array $header ## 响应头
- * @param int $options ## 其他信息
- * @return \Illuminate\Http\JsonResponse
- *
- * 接口返回格式 | 成功
- */
- public function apiResponseSuccess( $msg = '',$data = [], $code = 1, $status = 200, $header = [], $options = 0)
- {
- $this->lang();
- $msg=__($msg);
- return response()->json([
- 'msg' => $msg,
- 'data' => empty($data) ? [] : $data,
- 'code' => $code,
- ], $status, $header, $options);
- }
- /**
- * @param array $data ## 返回数据
- * @param string $msg ## 返回信息 如:auth.failed
- * @param int $code ## 响应编码 1:成功 0:失败
- * @param int $status ## HTTP响应状态 200:请求成功
- * @param array $header ## 响应头
- * @param int $options ## 其他信息
- * @return \Illuminate\Http\JsonResponse
- *
- * 接口返回格式 | 失败
- */
- public function apiResponseError( $msg = '',$data = [], $code = 0, $status = 200, $header = [], $options = 0)
- {
- $this->lang();
- $msg=__($msg);
- return response()->json([
- 'msg' => $msg,
- 'data' => empty($data) ? [] : $data,
- 'code' => $code,
- ], $status, $header, $options);
- }
- /**
- * 双语设置
- */
- protected function lang()
- {
- app()->setLocale(request()->input('lang', 'zh-Hans'));
- }
- }
|