Laravel Cashier DateTime :: __ construct():无法解析位置0(@)处的时间字符串(@): [英] Laravel Cashier DateTime::__construct(): Failed to parse time string (@) at position 0 (@):

查看:161
本文介绍了Laravel Cashier DateTime :: __ construct():无法解析位置0(@)处的时间字符串(@):的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当显示发票清单时,我有此代码,它与Laravel Cashier官方文档中的相似或完全相同.我收到这个奇怪的DateTime::__construct(): Failed to parse time string (@) at position 0 (@): Unexpected character错误,我不确定@字符在替换应该为日期的字符是什么.

I have this code when displaying list of invoices, this is similar or maybe exactly the same to the ones in the official Laravel Cashier documentation. I am getting this weird DateTime::__construct(): Failed to parse time string (@) at position 0 (@): Unexpected character error and I'm not sure what's the @ character doing in replace of a supposed to be date.

@foreach (Auth::user()->invoices() as $invoice)
    <tr>
        <td>{{ $invoice->date()->toFormattedDateString() }}</td>
        <td>{{ $invoice->total() }}</td>
        <td>
            <a href="/user/invoice/{{ $invoice->id }}">Download</a>
        </td>
    </tr>
@endforeach

有人有类似的经历吗?我还尝试仅var_dump控制器中的每个$invoice->date(),但错误仍然相同.

Does anyone have a similar experience? I have also tried to just var_dump each $invoice->date() in the controller but the error is still the same.

推荐答案

似乎您使用的不是最新版本的Laravel Cashier.在旧版本中,如果您遵循该代码,将会看到Laravel Cashier试图格式化Stripe不再返回的属性.

It seems like you're not using the most upto date version of Laravel Cashier. In older versions, if you follow the code through, you'll see that Laravel Cashier is trying to format a property that Stripe no longer returns.

cashier \ src \ Invoice.php,第48行

$carbon = Carbon::createFromTimestampUTC($this->invoice->date);

根据Stripe的"API升级指南",您可以在2019-03-14上看到他们宣布了以下更改;

As per the Stripe "API Upgrade Guide", you can see on 2019-03-14, they announced the following change;

日期属性已重命名为创建." (来源: https://stripe.com/docs/upgrades#2019-03-14 )

"The date property has been renamed to created." (Source: https://stripe.com/docs/upgrades#2019-03-14)

最新版本的Cashier通过首先检查created属性的存在来解决此问题.

The latest version of Cashier has addressed this issue by checking for the existance of the created property first.

https://github.com/laravel/cashier /blob/9.0/src/Invoice.php#L48

如果由于某种原因而无法升级,则代替:

If you can't upgrade for whatever reason, instead of:

$invoice->date()->toFormattedDateString()

您可以尝试以下操作:

Carbon::createFromTimestamp($invoice->asStripeInvoice()->created)->toFormattedDateString();

这篇关于Laravel Cashier DateTime :: __ construct():无法解析位置0(@)处的时间字符串(@):的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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