<?php

namespace App\Http\Controllers;

use Laravel\Lumen\Routing\Controller;

class BaseController extends Controller
{
    //
    /**
     * 成功返回Json数据
     * @param string $message 提示信息
     * @param array $data 数据
     * @param int $code 成功返回时的代码
     * @return \Illuminate\Http\JsonResponse
     */
    public function jsonResponse($message = '', $data = [], $code = 0)
    {
        if(empty($message)&&!empty($code)){
            $message=config('error')[(int) $code];
        }
        return response()->json([
            'code'    => $code,
            'message' => $message,
            'data'    => $data,
        ]);
    }
}
