如何使用 guzzle 在 cURL Laravel 中使用基本身份验证

How to use basic auth in cURL Laravel using guzzle

我需要为 razorpay 订单 ID 制作 cURL

它使用基本身份验证

我需要让这个 api 在 laravel 8

中工作

通过使用下面的代码,您可以构建所需的 cURL

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Http;

class PayController extends Controller

public function order(Request $request)

{

 $key = "YOUR API KEY";
 $secret = "YOUR API SECRET";
 $receipt = "unique recipt no"
 $amount = "1000"
 $currency = "INR"

    $client = new Client();
    $response = Http::withBasicAuth($key,$secret)
    ->post('https://api.razorpay.com/v1/orders',
      [
        'receipt'=> $receipt,
        'amount'=> $amount,
        'currency'=> $currency
      ]
);