Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
515 B
1
Indexable
Never
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);
}
Leave a Comment