How to get data from api using laravel controller

Solution:

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;
    }