laravel-json-api / laravel

JSON:API for Laravel applications
MIT License
523 stars 43 forks source link

Error when handling validation failures #287

Closed nvahalik closed 1 week ago

nvahalik commented 1 week ago

Appears that how shift() works on a collection has changed:

Laravel v10.48.12:

$a = collect();
$a->shift(); // null

Laravel v10.48.13

$a = collect();
$a->shift(); // Collection

The result of null when calling ->shift() changed with this Framework PR.

This causes a problem when returning errors during validation:

https://github.com/laravel-json-api/validation/blob/2c883a5d1727cd8683deed74167956471a82272a/src/ErrorIterator.php#L115

The Elvis operator here won't fall-through to the empty array.

asugai commented 1 week ago

@nvahalik - looks like this is patched and may be fixed in the next point release on the framework side to return null again - https://github.com/laravel/framework/pull/51841

nvahalik commented 1 week ago

D'oh!

I guess I misunderstood. The PR actually fixes the problem. Doesn't cause it.

lindyhopchris commented 1 week ago

Just for safety, I've switched it to using array_shift instead, and I've tagged that as v3.0.1 (as the bug was in Laravel 10).

lindyhopchris commented 1 week ago

Also merged the change into the Laravel 11 version, tagging v4.1.1.

lindyhopchris commented 1 week ago

FYI both those version numbers apply to the laravel-json-api/validation package.