Skip to content

Fix: Add datetime cast for ends_at column #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

raseldev99
Copy link

Issue

When using the package with MySQL, I encountered the following error:
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2025-04-28T06:47:00.000Z' for column 'ends_at'

This happens because the ends_at column is receiving ISO 8601 formatted dates that MySQL cannot properly interpret without casting.

Solution

I've added a simple datetime cast to the model:

protected array $casts = [
    'ends_at' => 'datetime'
];
This ensures Laravel properly formats the datetime before sending it to the database, preventing the SQL format error.

Testing

I've tested this fix with:
MySQL 8.0
Laravel 10.x
PHP 8.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant