It looks like the issue you're encountering is related to how Laravel is handling the version_date field. By default, Laravel treats created_at and updated_at fields as Carbon instances and applies the timezone settings correctly. However, for custom datetime fields like version_date, you need to explicitly tell Laravel to treat them as Carbon instances and apply the timezone settings.
Here's how you can solve this issue:
-
Ensure the
version_datefield is cast to a datetime in your model:In your
VersionConfigDatemodel, you should add theversion_datefield to the$castsproperty to ensure it is treated as a datetime.class VersionConfigDate extends Model { protected $casts = [ 'version_date' => 'datetime', ]; } -
Set the timezone in your
AppServiceProvider:You can set the default timezone for Carbon instances in the
bootmethod of yourAppServiceProvider.use Illuminate\Support\Carbon; class AppServiceProvider extends ServiceProvider { public function boot() { // Set the default timezone for Carbon Carbon::setLocale(config('app.timezone')); } } -
Check your database connection configuration:
Ensure that your database connection configuration in
config/database.phpis set to use the correct timezone.'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', '127.0.0.1'), 'port' => env('DB_PORT', '3306'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'unix_socket' => env('DB_SOCKET', ''), 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', 'strict' => true, 'engine' => null, 'timezone' => env('DB_TIMEZONE', '+00:00'), ], -
Verify the timezone in your
.envfile:Ensure that the timezone is correctly set in your
.envfile.APP_TIMEZONE=America/New_York DB_TIMEZONE=+00:00
By following these steps, you should be able to ensure that the version_date field is treated correctly with the appropriate timezone settings. This should resolve the issue of the time defaulting to midnight UTC.