1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Foundation\Bus\DispatchesJobs;
- use Illuminate\Routing\Controller as BaseController;
- use Illuminate\Foundation\Validation\ValidatesRequests;
- use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
- class Controller extends BaseController
- {
- use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
- protected $error;
- function __construct()
- {
- $this->error = config("errorcode");
- }
- /**
- * HTTP请求成功时的数据返回
- *
- * @param array $data
- * @param string $message
- * @return \Illuminate\Http\JsonResponse
- */
- public function success($data = array(), $message = "success")
- {
- $return = array(
- 'code' => REQUEST_SUCCESS,
- 'message' => $message,
- 'data' => $data
- );
- return response()->json($return);
- }
- /**
- * HTTP请求失败时错误信息返回
- *
- * @param $code
- * @param string $codeMessage
- * @param null $message
- * @return \Illuminate\Http\JsonResponse
- */
- public function fail($code, $codeMessage = "", $message = null)
- {
- return response()->json([
- 'code' => (int)$code,
- "codeMessage" => $codeMessage,
- 'message' => $message
- ]);
- }
- /**
- * HTTP请求响应
- *
- * @param $code
- * @param string $codeMessage
- * @param null $message
- * @return \Illuminate\Http\JsonResponse
- */
- public function response($code, $codeMessage = "", $message = null)
- {
- return response()->json([
- 'code' => (int)$code,
- "codeMessage" => $codeMessage,
- 'message' => $message
- ]);
- }
- }
|