【问题标题】:Date Issue in Laravel Cashier InvoiceLaravel Cashier Invoice 中的日期问题
【发布时间】: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-&gt;date()-&gt;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-&gt;newSubscription('eat', 'eat_monthly')-&gt;create($request-&gt;stripeToken); 的代码,但此方法创建的所有记录都有一个 NULL 日期。
  • 也许可以尝试在控制器中转储您的订阅信息,以在将其存储到数据库之前检查它是否通过 - 如果值在那里,我们可以从那里工作:)

标签: laravel laravel-cashier


【解决方案1】:

而不是{{ $invoice-&gt;date()-&gt;toFormattedDateString() }}

你能试试{{ $invoice-&gt;created_at-&gt;toFormattedDateString() }}吗?

【讨论】:

  • 是的,这可以在发票列表中使用,但在生成发票时,我仍然会收到错误,因为 $invoice->date() 为 NULL。
  • 我试过这个,但得到一个Call to a member function toFormattedDateString() on int 错误。最终使用Carbon::createFromTimestampUTC($invoice-&gt;created)
【解决方案2】:

Stripe 已将 date 参数更改为 created 有效。
这样使用:{{ $invoice-&gt;created }}

【讨论】:

    猜你喜欢
    • 2020-01-16
    • 2020-12-02
    • 2017-05-25
    • 2020-11-09
    • 2019-11-25
    • 1970-01-01
    • 2015-10-15
    • 1970-01-01
    • 2017-11-28
    相关资源
    最近更新 更多