You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
761 B
31 lines
761 B
<?php
|
|
|
|
namespace App\Http;
|
|
use \Illuminate\Http\JsonResponse;
|
|
|
|
trait JsonReturn
|
|
{
|
|
/**
|
|
* 成功返回
|
|
* @param $data
|
|
* @param string $message
|
|
* @param int $code
|
|
* @return JsonResponse
|
|
*/
|
|
public static function success($data, string $message = '成功', int $code = 0): JsonResponse
|
|
{
|
|
return response()->json(['code' => $code, 'data' => $data, 'message' => $message]);
|
|
}
|
|
|
|
/**
|
|
* 失败返回
|
|
* @param string $message
|
|
* @param int $code
|
|
* @param $data
|
|
* @return JsonResponse
|
|
*/
|
|
public static function error(string $message, int $code = 1, $data = null): JsonResponse
|
|
{
|
|
return response()->json(['code' => $code, 'data' => $data, 'message' => $message]);
|
|
}
|
|
}
|