You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When an empty string is persisted on a datetime column in the database and that column is casted by 'datetime' cast, you get current datetime instead of null as the output.
Steps To Reproduce
create a migration which includes a datetime column as such: $table->dateTime('approved_at')->nullable();
On the model class, cast the attribute using 'datetime' cast as such: protected function casts(): array { return [ 'approved_at' => 'datetime', ]; }
Let us assume that we have a Post model and store some date as such: Post::create(['title' => 'Laravel', 'approved_at' => '']);
And finally, let's try to access the 'approved_at' field as such: $post->approved_at;
Expected result: null or '' Outcome: current datetime (i.e. same as now() method)
The text was updated successfully, but these errors were encountered:
Laravel Version
11.5.0
PHP Version
8.3.4
Database Driver & Version
SQLite 3.19.1 for Windows 11
Description
When an empty string is persisted on a datetime column in the database and that column is casted by 'datetime' cast, you get current datetime instead of null as the output.
Steps To Reproduce
$table->dateTime('approved_at')->nullable();
protected function casts(): array { return [ 'approved_at' => 'datetime', ]; }
Post::create(['title' => 'Laravel', 'approved_at' => '']);
$post->approved_at;
Expected result: null or ''
Outcome: current datetime (i.e. same as now() method)
The text was updated successfully, but these errors were encountered: