<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ResponseController extends Controller{
    public function makeResponse($error, $msg, $response = [], $code = 200){
        $respuesta = json_encode([
            "error" => $error,
            "msg" => $msg,
            "response" => $response
        ]);

        return response($respuesta, $code)->header('Content-Type', 'application/json');
    }

    public function makeErrors($erroresObj){
        $erroresArr = array();

        foreach($erroresObj as $key => $value){
            foreach($value as $key0 => $value0){
                if(array_key_exists($key, $erroresArr)){
                    $val = $erroresArr[$key] . "|" . $value0;
                    $erroresArr[$key] = $val;
                }else{
                    $erroresArr[$key] = $value0;
                }
            }
        }

        return $erroresArr;
    }
}
