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
This commit is contained in:
23
core/app/Models/Concerns/StoresUtc.php
Normal file
23
core/app/Models/Concerns/StoresUtc.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user