0
votes

i have an api that will return JWT Token https://i.stack.imgur.com/qWr85.png

how do i take the data using laravel controller, i've tried using GuzzleHttp\Client

        $client = new Client();
        $url = 'http://127.0.0.1:8000/api/login';
        $response = $client->request('GET', $url, [
            'query' => [
                'username' => $request->username,
                'password' => $request->password,
            ],
        ]);

And this is the result https://i.stack.imgur.com/PZfe0.png and this if i tried to dd the $response body https://i.stack.imgur.com/KQTjG.png

1
welcome to so, have you tried $response->getBody()->getContents()bhucho

1 Answers

2
votes

You should use CURL for it.

function name_of_the_function(Request $request){
    $url = "http://127.0.0.1:8000/api/login?username=".$request->username."&password=".$request->password;
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
    $err = curl_error($ch);
    $response = curl_exec($ch);
    if ($err) {
     echo "cURL Error #:" . $err;
    }
    curl_close($ch);
    return $response;
    }