fix: Fix API store con le date

This commit is contained in:
Maicol Battistini 2023-06-19 11:45:54 +02:00
parent d36d9f84fe
commit db6a263415
No known key found for this signature in database
1 changed files with 19 additions and 0 deletions

View File

@ -15,14 +15,17 @@ use Binaryk\LaravelRestify\Http\Requests\RepositoryAttachRequest;
use Binaryk\LaravelRestify\Http\Requests\RepositorySyncRequest; use Binaryk\LaravelRestify\Http\Requests\RepositorySyncRequest;
use Binaryk\LaravelRestify\Http\Requests\RestifyRequest; use Binaryk\LaravelRestify\Http\Requests\RestifyRequest;
use Binaryk\LaravelRestify\Repositories\Repository as RestifyRepository; use Binaryk\LaravelRestify\Repositories\Repository as RestifyRepository;
use Carbon\Exceptions\InvalidFormatException;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Support\Arr; use Illuminate\Support\Arr;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use function in_array; use function in_array;
use function is_array; use function is_array;
use function is_string;
use Nette\Utils\Json; use Nette\Utils\Json;
@ -271,6 +274,22 @@ abstract class Repository extends RestifyRepository
} }
} }
// Fix dates (JSONAPI uses ISO 8601, Restify uses Y-m-d H:i:s)
$attributes = array_map(
static function ($value) {
if (is_string($value)) {
try {
return Carbon::parse($value)->format('Y-m-d H:i:s');
} catch (InvalidFormatException) {
return $value;
}
}
return $value;
},
$attributes
);
$request->replace([ $request->replace([
...$attributes, ...$attributes,
...$relationships, ...$relationships,