Skip to content

Comments

fix: Laravel 12.45.x ResourceCollection compatibility#482

Merged
kevalyq merged 1 commit intomainfrom
fix/laravel-12-45-resource-collection
Jan 7, 2026
Merged

fix: Laravel 12.45.x ResourceCollection compatibility#482
kevalyq merged 1 commit intomainfrom
fix/laravel-12-45-resource-collection

Conversation

@kevalyq
Copy link
Contributor

@kevalyq kevalyq commented Jan 7, 2026

Summary

Fixes test failures in all Dependabot PRs (#478, #479, #480, #481) caused by Laravel 12.45.0 breaking change in ResourceCollection handling.

Problem

Laravel 12.45.0 introduced PR #58299 which changed how ResourceCollection::collection() handles plain arrays vs Model Collections. The test SecretAttachmentResourceTest > resource transforms collection correctly was passing a plain array, which now returns incorrect data structure.

Failing Test:

$collection = SecretAttachmentResource::collection([$attachment1, $attachment2]);
// Returns: [null, null] instead of proper attachment data

Error:

FAILED  Tests\Feature\Resources\SecretAttachmentResourceTest > resource transforms collection correctly
Failed asserting that null is identical to 'file1.pdf'.
at tests/Feature/Resources/SecretAttachmentResourceTest.php:108

Solution

Wrap the array in collect() to ensure proper Collection type:

$collection = SecretAttachmentResource::collection(collect([$attachment1, $attachment2]));

This ensures the ResourceCollection receives an Eloquent Collection instead of a plain array, maintaining compatibility with Laravel 12.45.x.

Testing

  • ✅ Local: PHPStan Level 9 clean
  • ✅ Local: Laravel Pint (PSR-12) compliant
  • ✅ CI will verify: All 1817 tests pass

Impact

Related

Laravel 12.45.0 introduced a breaking change in ResourceCollection
handling (PR laravel/framework#58299). Collections created from
plain arrays no longer work correctly.

Fix: Wrap array in collect() to ensure proper Collection type.

Related: #479, #480, #481, #478 (Dependabot PRs)
Copilot AI review requested due to automatic review settings January 7, 2026 19:54
@github-actions
Copy link

github-actions bot commented Jan 7, 2026

💡 Tip: Consider Using Draft PRs

Benefits of opening PRs as drafts initially:

  • 💰 Saves CI runtime and Copilot review credits
  • 🎯 Automatically sets linked issues to "🚧 In Progress" status
  • 🚀 Mark "Ready for review" when done to trigger full CI pipeline

How to convert:

  1. Click "Still in progress? Convert to draft" in the sidebar, OR
  2. Use gh pr ready when ready for review

This is just a friendly reminder - feel free to continue as is! 😊

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a test failure caused by Laravel 12.45.0's breaking change in ResourceCollection handling, which now requires proper Collection types instead of plain arrays for correct data transformation.

Key Changes

  • Wraps test array in collect() to ensure SecretAttachmentResource::collection() receives an Eloquent Collection instead of a plain array
  • Maintains compatibility with Laravel 12.45.x while preserving test functionality

@codecov
Copy link

codecov bot commented Jan 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@kevalyq kevalyq merged commit 05107b0 into main Jan 7, 2026
27 checks passed
@kevalyq kevalyq deleted the fix/laravel-12-45-resource-collection branch January 7, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant