Untitled

 avatar
unknown
plain_text
a year ago
515 B
2
Indexable
function apiResponse($success, $msg, $data, $httpStatusCode=null, bool $isMeta=false){
    $response = [
        'success' => $success,
        'msg' => $msg,
        'data' => $isMeta ? $data->toArray()['data'] : $data,
        // 'meta' => $meta
    ];
    if($isMeta){
        $response['meta'] = ['current_page' => $data->toArray()['current_page'], 'limit' => $data->toArray()['to'], 'total' => $data->toArray()['total']];
    }
    return response()->json($response, $httpStatusCode ? $httpStatusCode : 200);
}
Editor is loading...
Leave a Comment