Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

oblioscajovy's avatar

How to convert this CURL request structure into LARAVEL approach?

    <?php 
    
    $data = array(
        '_ip' => "00.000.00.000",
        '_data' => array(
            '_token'=> 'vxxxxxxx',
            'url'=> 'http://localhost/sampleapi/',
            'destination'=> 'New York City',
            'hotelcheckin'=> '2018-10-12',
            'hotelcheckout'=> '2018-10-13',
            'rooms'=> '1',
            'guests_count'=> '1 Adult + 1 Child',
            'adult' =>'1',
            'child'=>'1',
            'childage1'=>'1'
        )
    );



$retrieve = curlRequest( $data );


print_r($retrieve);

function curlRequest($return){
    $data = base64_encode(bin2hex(json_encode($return)));
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,"https://sample.com/hotel-query?_data=".$data); 
        curl_setopt($ch, CURLOPT_POST, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $output = curl_exec($ch);
        curl_close($ch);
        return $output; 
    }

?>

Its working in the traditional way but I want to know how it works in laravel. I dont know where specifically put the code in laravel... I am a newbie in laravel. *Any help will do Sir and Maam. Thank you!

0 likes
0 replies

Please or to participate in this conversation.