I have a controller that accesses the method searchUserByName
of another controller and returns a JsonResponse
, this variable $user
I understand that it is a Json right? If I want to get the value of the result that is inside, how should I do it?
/**
* @param Request $request
* @return JsonResponse
*/
public function uploadSubmit(Request $request)
{
foreach($request->file('file') as $file){
try {
...
...
$user = app('App\Http\Controllers\UserController')
->searchUserByName($attributes['name']);
}
catch (\Exception $e) {
var_dump($e->getMessage());
}
}
}
/**
* @param $name
* @return Response
*/
public function searchUserByName($name)
{
try {
$user = User::where('name', 'like', '%'.$name.'%')->get();
}
catch (\Exception $exception) {
return response()->json([
'errors' => ['Error'],
], 500);
}
return new JsonResponse([
'data' => $user,
]);
}