Laravel Cashier Invoice Date Issue

我怕爱的太早我们不能终老 提交于 2019-12-25 03:28:35

问题


I am using Laravel 5.8 with Laravel Cashier. When I try to show a list of invoices of a user, I used this code:

@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

However, the line $invoice->date()->toFormattedDateString() gives an error:

DateTime::__construct(): Failed to parse time string (@) at position 0 (@): Unexpected character

It seems that the Invoice date is null. Are there other settings that I should follow? Downloading the invoice will also produce an error because of the Invoice date.

EDIT: I edited the Laravel Invoice class (vendor\laravel\laravel\cashier\Invoice.php) to print the real date and it turns out, the invoice date is NULL.

/**
 * Get a Carbon date for the invoice.
 *
 * @param  \DateTimeZone|string  $timezone
 * @return \Carbon\Carbon
 */
public function date($timezone = null)
{
    echo("HERE <br />");
    var_dump($this->invoice->date);
    exit();
    $carbon = Carbon::createFromTimestampUTC($this->invoice->date);

    return $timezone ? $carbon->setTimezone($timezone) : $carbon;
}

The var_dump($this->invoice->date); returns NULL.

来源:https://stackoverflow.com/questions/55685197/laravel-cashier-invoice-date-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!