I need to include $ token within the $ user array where I save my query, I'm using the laravel 5.5 framework
protected function respondWithToken($token,$documento){
$user = User::select('id','nombre','email')->where('documento', $documento)->get();
$token = [
'access_token' => $token,
'token_type' => 'bearer'
];
return $user;
}
I know that I can join and concatenate within an array function but it would stay that way, and it's not the way I look. I want to include it in a single array.
{
"user": [
{
"id": 2,
"nombre": "Pedro",
"email": "[email protected]"
}
],
"token": "sfgt854dfgdf54dfg5df4gdf98g4df",
"token_type": "bearer"
}
I need to include that variable token inside my object and return a json in this way
[
{
"id": 2,
"nombre": "Pedro",
"email": "[email protected]",
"token": "sdjkfhsdk65468541sdf3"
}
]