46 lines
1.8 KiB
PHP
46 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Casts;
|
|
|
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class NiceDate implements CastsAttributes
|
|
{
|
|
/**
|
|
* Cast the given value.
|
|
*
|
|
* @param \Illuminate\Database\Eloquent\Model|null $model
|
|
* @param string $key
|
|
* @param mixed $value
|
|
* @param array $attributes
|
|
* @return string
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceAfterLastUsed
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed
|
|
*/
|
|
public function get(Model|null $model, string $key, mixed $value, array $attributes): string
|
|
{
|
|
// phpcs:enable
|
|
$value = Carbon::parse($value);
|
|
return $value->isToday() ?
|
|
trans('Aujourd\'hui à :time', ['time' => $value->format('H:i')]) : $value->format('Y/m/d à H:i');
|
|
}
|
|
|
|
/**
|
|
* Prepare the given value for storage.
|
|
*
|
|
* @param \Illuminate\Database\Eloquent\Model $model
|
|
* @param string $key
|
|
* @param mixed $value
|
|
* @param array $attributes
|
|
* @return string
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceAfterLastUsed
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed
|
|
*/
|
|
public function set(Model $model, string $key, mixed $value, array $attributes): string
|
|
{
|
|
// phpcs:enable
|
|
return Carbon::parse($value)->format('Y-m-d H:i:s');
|
|
}
|
|
}
|