laravel-paystack-subscription
laravel-paystack-subscription copied to clipboard
Fix: Add datetime cast for ends_at column
trafficstars
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