我正在使用Laravel 5.8和Laravel Cashier。当我尝试显示用户发票列表时,我使用了以下代码:
@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
但是,行$invoice->date()->toFormattedDateString()
给出了错误:
DateTime::__construct(): Failed to parse time string (@) at position 0 (@): Unexpected character
发票日期似乎为空。还有其他应遵循的设置吗?由于发票日期,下载发票也会产生错误。
编辑: 我编辑了Laravel发票类(vendor \ laravel \ laravel \ cashier \ Invoice.php)以打印真实日期,事实证明,发票日期为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;
}
var_dump($this->invoice->date);
返回NULL。
答案 0 :(得分:0)
只需替换:
$this->invoice->date
收件人:
$this->invoice->created