I am new to laravel 8 and I am working on an existing project. There is a function that returns a json response :
public function ReturnTest($num) {
return response()->json(array('test done succesfully',$num),200);
}
and I want to use that returned array in the backend in this function :
public function ViewPage() {
/* $data = DB::select('select * from domaines');
dd($data);*/
$var=$this->ReturnTest(25);
dd($var);
}
this is the result :
Illuminate\Http\JsonResponse {#290 ▼
#data: "["test done succesfully",25]"
#callback: null
#encodingOptions: 0
headers: Symfony\Component\HttpFoundation\ResponseHeaderBag {#291 ▶}
#content: "["test done succesfully",25]"
#version: "1.0"
#statusCode: 200
#statusText: "OK"
#charset: null
original: array:2 [▶]
exception: null
}
CodePudding user response:
If you really had to do things this way you could call getData on the Response to get the decoded (json_decode) version of the data:
$var->getData();
CodePudding user response:
Why you don't just return your response without wrapping it up?
public function ReturnTest($num) {
return array('test done succesfully',$num);
}
