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.