In my laravel request I am sending data as given below..
{
"user_id":13,
"location":null,
"about":"This Is About the user",
"avatar":[],
"users":[
{
"user_name":"John",
"age":"30",
},
{
"user_name":"Jessy",
"age":"30",
}
]
}
All the request keys can be null or hold a value (an array or string) so I want to filter only keys which has value.
Expected Output:
{
"user_id":13,
"about":"This Is About the user",
"users":[
{
"user_name":"John",
"age":"30",
},
{
"user_name":"Jessy",
"age":"30",
}
]
}
I have tried
$userRequestData = $request->only([
'location','about','avatar','users'
]);
$Data = array_filter($userRequestData, 'strlen');
But it only works if the request has only string values...
How can I filter it even if it's a string or an array?
user_namekey inside users?