I have the following code, but when I am going to pass values to the view I get the error Trying to get property of non-object .
Does anyone know what I'm doing wrong?
In the control path:
Route::get('test2', function(){
$client = new Client();
$response = $client->post("http://Myruta.com/login", [
'headers' => ['foo' => 'bar'],
'json' => [
'email' => '[email protected]',
'password' => 'test',
]
]);
$user = json_decode( $response->getBody()->getContents() );
return view('welcome', compact('user'));
});
In the view:
{{$user->user_name}}
Result:
Trying to get property of non-object (View: ....