【发布时间】:2019-04-26 06:54:46
【问题描述】:
我有这个代码可以查看我页面中的所有发票:
@foreach ($user->invoices() as $invoice)
<tr>
<td>{{ $invoice->date()->toFormattedDateString() }}</td>
<td>{{ $invoice->total() }}</td>
<td>
<a href="/invoice/{{ $invoice->id }}">Download</a>
</td>
</tr>
@endforeach
但是,$invoice->date()->toFormattedDateString() 行给出了错误:
DateTime::__construct(): Failed to parse time string (@) at position 0 (@): Unexpected character
我只是按照 Laravel Cashier (Billing) 网站上的所有说明进行操作,但我收到了这个错误。我尝试了两个版本的 Laravel(5.8 和 5.5)和两个 Laravel Cashier 版本(8.0 和 7.0)。所有测试都有相同的日期问题。
我添加了正确的迁移字段。这就是我向我的数据库插入/添加订阅的方式:
$user = Auth::user();
$user->newSubscription('eat', 'eat_monthly')->create($request->stripeToken);
【问题讨论】:
-
您是否尝试过转储 $invoice->date() 以查看是否有任何原因 toFormattedDateString() 方法不起作用?
-
是的,我忘了说... $invoice->date() 为 NULL...
-
你为什么要将 NULL 转换为日期时间字符串?
-
这就是问题所在,Laravel Cashier 处理插入和更新的所有数据。这是我的主要问题,为什么它首先是 NULL 。这是添加订阅
$user->newSubscription('eat', 'eat_monthly')->create($request->stripeToken);的代码,但此方法创建的所有记录都有一个 NULL 日期。 -
也许可以尝试在控制器中转储您的订阅信息,以在将其存储到数据库之前检查它是否通过 - 如果值在那里,我们可以从那里工作:)