Files
hado/core/app/Models/Concerns/StoresUtc.php
nikita.hohlov e48e48aa4a feat: due resolution and cascade math
Also: StoresUtc trait normalizes datetime casts to UTC (controller ruling).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BCrwHHnGCB5XH968Nxokqw
2026-09-04 06:19:00 -03:00

24 lines
689 B
PHP

<?php
namespace App\Models\Concerns;
use Carbon\CarbonImmutable;
use DateTimeInterface;
/**
* Eloquent форматирует datetime без смещения, поэтому Carbon в чужом поясе
* записался бы как «те же цифры в UTC». Приводим к UTC при присвоении.
*/
trait StoresUtc
{
public function setAttribute($key, $value)
{
if ($value instanceof DateTimeInterface
&& in_array($this->getCasts()[$key] ?? null, ['datetime', 'immutable_datetime'], true)) {
$value = CarbonImmutable::instance($value)->utc();
}
return parent::setAttribute($key, $value);
}
}