Changes the preserveKeys property to use the PreserveKeys attribute
+use Illuminate\Http\Resources\Attributes\PreserveKeys;
use Illuminate\Http\Resources\Json\JsonResource;
+#[PreserveKeys]
class UserResource extends JsonResource
{
- protected $preserveKeys = true;
}
Configure your rector.php:
<?php
use RectorLaravel\Rector\Class_\PreserveKeysPropertyToPreserveKeysAttributeRector;
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withRules([
PreserveKeysPropertyToPreserveKeysAttributeRector::class,
]);