<?php


namespace App\Http\Controllers;

class BaseController extends Controller
{
    /**
     * @param array $data
     * @param bool $needObject 数据为空时是否需要以对象的方式返回
     * @param string $code
     * @param string $msg
     * @return \Illuminate\Http\JsonResponse
     */
    protected function getSuccessMsg($data = array(), $msg = '操作成功', $needObject = true, $code = '200')
    {
        return response()->json([
            'code' => $code,
            'msg' => $msg,
            'data' => $data ? $data : ($needObject ? (object)array() : []),
        ]);
    }

    protected function getErrorMsg($code = '', $msg = '')
    {
        return response()->json([
            'code' => $code,
            'msg' => $msg,
        ]);
    }

}

