Previously I asked a question about the same topic, but I still have problems with some views. I have a query or a result that throws an API to me using Guzzlehttp, which throws me the following array when I print with dd ($ user):
array:1 [▼
0 => {#187 ▶}
]
With this information:
array:1 [▼
0 => {#187 ▼
+"id": 555
+"email": "[email protected]"
+"company_id": null
+"user_name": "Pruebas localHost"
+"img": null
+"user_position": null
+"user_phone": null
+"user_type": "US"
+"user_validate": 0
+"user_id_facebook": null
+"user_conf_code": null
+"created_at": "2017-07-28 14:05:01"
+"updated_at": "2017-07-28 14:05:01"
}
]
With print_r($user);
Array ( [0] => stdClass Object ( [id] => 555 [email] => [email protected] [company_id] => [user_name] => Pruebas localHost [img] => [user_position] => [user_phone] => [user_type] => US [user_validate] => 0 [user_id_facebook] => [user_conf_code] => [created_at] => 2017-07-28 14:05:01 [updated_at] => 2017-07-28 14:05:01 ) )
The problem is that when I am going to take this information to the view I can not get the results Trying to get property of non-object
. I do not know what I'm doing wrong but I've used several methods and I always get the same error. the forms I've used: foreach
$user[0]['id']
{{$user->id}}
This is the driver I'm using:
public function login(Request $request){
$client = new Client();
$this->validate($request, [
'email' => 'email|required',
'password' => 'min:3|max:100',
]);
$response = $client->post("http://localhost:8000/v1/login", [
'headers' => ['foo' => 'bar'],
'json' => [
'email' => $request['email'],
'password' => $request['password'],
]
]);
$user = json_decode($response->getBody()->getContents());
dd($user);
//return view('pages.home')->with('user', $user); --> No funciona
//return view('pages.home', compact('user')); ---> No funciona
}
In the view:
@foreach($user as $user)
<li> {{$user->id}}" </li>
@endforeach
I also tried
<li> {{$user->id}}" </li>
How should I pass the variable correctly to my views?