2024-07-11 15:46:43 +02:00
|
|
|
<?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.
|
|
|
|
|
*
|
|
|
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceAfterLastUsed
|
2026-09-25 16:25:31 +02:00
|
|
|
*
|
2024-07-11 15:46:43 +02:00
|
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed
|
|
|
|
|
*/
|
2026-09-25 16:25:31 +02:00
|
|
|
public function get(?Model $model, string $key, mixed $value, array $attributes): string
|
2024-07-11 15:46:43 +02:00
|
|
|
{
|
|
|
|
|
// phpcs:enable
|
|
|
|
|
$value = Carbon::parse($value);
|
2026-09-25 16:25:31 +02:00
|
|
|
|
2024-07-11 15:46:43 +02:00
|
|
|
return $value->isToday() ?
|
2024-07-15 11:09:34 +02:00
|
|
|
trans('Aujourd\'hui à :time', ['time' => $value->format('H:i')]) : $value->format('Y/m/d à H:i');
|
2024-07-11 15:46:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Prepare the given value for storage.
|
|
|
|
|
*
|
|
|
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceAfterLastUsed
|
2026-09-25 16:25:31 +02:00
|
|
|
*
|
2024-07-11 15:46:43 +02:00
|
|
|
* @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');
|
|
|
|
|
}
|
|
|
|
|
}
|