rappasoft / laravel-livewire-tables

A dynamic table component for Laravel Livewire
https://rappasoft.com/docs/laravel-livewire-tables/v2/introduction
MIT License
1.7k stars 319 forks source link

[Bug]: DateColumn throws error on NULL values when using date format #1724

Closed nathanmay closed 3 weeks ago

nathanmay commented 1 month ago

What happened?

When using a date column and formatting the date output. When a NULL value is recevied an error is thrown. Even when using ->emptyValue('Not Found') as per docs.

How to reproduce the bug

Set columns

public function columns(): array
    {
        return [
            Column::make("Id", "id")
                ->sortable(),
            Column::make("Booking id", "booking.ref")
                ->sortable()
                ->searchable(),
            Column::make("Invoice id", "invoice.inv_number")
                ->sortable()
                ->searchable(),
            Column::make("Staff id", "staff.first_name")
                ->sortable()
                ->searchable(),
            DateColumn::make("Paid date", "paid_date")
                ->sortable()
                ->emptyValue('NOT PAID YET')
                ->outputFormat('d/m/Y'),
            Column::make('Actions')
                ->label(
                    fn($row, Column $column) => view('livewire.commission.commission-table-actions')->with(
                        [
                            'id' => $row->id,
                        ]
                    )
                )->html(),
        ];
    }

Have record in Databse that is NULL.

Error is thrown:

Carbon\Factory::hasFormatWithModifiers(): Argument #1 ($date) must be of type string, null given, called in C:\laragon\www\pems\vendor\nesbot\carbon\src\Carbon\Traits\Comparison.php on line 822

Package Version

3.2.5

PHP Version

8.2.x

Laravel Version

11.8.0

Alpine Version

No response

Theme

Tailwind 3.x

Notes

Running Livewire 3.5

Error Message

Carbon\Factory::hasFormatWithModifiers(): Argument #1 ($date) must be of type string, null given, called in C:\laragon\www\pems\vendor\nesbot\carbon\src\Carbon\Traits\Comparison.php on line 822

lrljoe commented 1 month ago

Should be fixed this weekend, have the fix, just need to check that it doesn't impact any of the tests etc

1726

lrljoe commented 1 month ago

Is now in develop should you wish to test it, should be a new release this weekend.

nathanmay commented 1 month ago

@lrljoe tested in my environment and I can confirm it is fixed. Thank you! 👍

lrljoe commented 1 month ago

I plan to do a release tomorrow which will be everything in develop.

Then there's another release coming shortly which adds some Header Action capabilities.

And there's an ArrayColumn which I need to document and write tests for.

At some point I'll add a bleeding-edge branch for anything that isn't ready for release due to docs/tests being missing, as develop does require those to be present.

lrljoe commented 3 weeks ago

The fix for this should be in the latest version, if you still have issues, then please re-open the issue/reply/reach out on Discord!