(更新)Laravel PUT方法不起作用 [英] (Updated) Laravel PUT Method Not Working

查看:545
本文介绍了(更新)Laravel PUT方法不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 已更新-JSON文件将返回,但完全不会更改结算日期.

  • updated - the JSON file would return but it will not change the billing date at all.

参考文献1 :有关 Reference2 :其示例代码的详细信息:

Reference2: their sample code in detail:

<?php

$request = new HttpRequest();
$request->setUrl('https://domain.chargify.com/subscriptions/$subscriptionId.json');
$request->setMethod(HTTP_METH_PUT);

$request->setHeaders(array(
  'authorization' => 'Basic YXBpa2V5Og==',
  'content-type' => 'application/json'
));

$request->setBody('{"subscription":{"next_billing_at":"2028-12-15"}}');

try {
  $response = $request->send();
  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}

我的详细代码:

   public function changeYearlySubscriptionBillingDate(Request $request)
{
    $user = $request->user();
    $subscriptionId = $user->subscription->subscription_id;
    $nextBilling = Carbon::now()->addYear();
    $hostname = env('CHARGIFY_HOSTNAME');

    $headers = [
        'authorization' => 'Basic ANIDIANDIAJIJCQ',
        'content-type' => 'application/json'
    ];

    $body = ["subscription" => ["next_billing_at" =>[ $nextBilling ]]];

    $config = [
        'headers' => $headers,
        'form_param' => $body
    ];

    $client = new Client($config);

    $res = $client->put("https://$hostname/subscriptions/$subscriptionId.json",
    ["json" => [
    [ "subscription" =>
        [ "next_billing_at" => $nextBilling ]
    ]
]
]);

    echo $res->getBody();
}

推荐答案

非常感谢大家对我的帮助.

thanks everyone so much for helping me out.

我已经在这个问题上工作了2天了,应该认为这对我来说是正确的.最终,是他们的API误导了我.

I've been working on this problem for 2 days and it was supposed to be right to me. Eventually, it is their API that misled me.

我们唯一需要做的就是改变

the only thing we need to do, is simply change

'body' => "{\"subscription\":{\"next_billing_at\":\"$nextBilling\"}}"

在其中添加了一些'\'.

added a few '\' s inside.

感谢大家为我提供帮助,祝您有美好的一天!

Thanks everyone for helping me out, have a good day!

这篇关于(更新)Laravel PUT方法不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆