ldc-legaulois/app/Casts/NiceDate.php

24 lines
760 B
PHP
Raw Normal View History

2021-03-10 17:16:31 +01:00
<?php
namespace App\Casts;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Support\Carbon;
2021-03-21 22:51:19 +01:00
//phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceAfterLastUsed
//phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed
2021-03-10 17:16:31 +01:00
class NiceDate implements CastsAttributes
{
public function get($model, $key, $value, $attributes)
{
$value = Carbon::parse($value);
return $value->isToday() ?
2021-03-19 21:40:10 +01:00
trans('Aujourd\'hui à :time', ['time' => $value->format('H:i')]) : $value->format('Y/m/d H:i');
2021-03-10 17:16:31 +01:00
}
public function set($model, $key, $value, $attributes)
{
return Carbon::parse($value)->format('Y-m-d H:i:s');
}
}