Skip to content

[12.x] Fix File::types() silently discarding chain configuration#59324

Draft
JoshSalway wants to merge 2 commits intolaravel:12.xfrom
JoshSalway:fix/file-types-static-method
Draft

[12.x] Fix File::types() silently discarding chain configuration#59324
JoshSalway wants to merge 2 commits intolaravel:12.xfrom
JoshSalway:fix/file-types-static-method

Conversation

@JoshSalway
Copy link
Copy Markdown
Contributor

@JoshSalway JoshSalway commented Mar 22, 2026

Summary

Fixes File::types() silently discarding prior chain configuration when called as an instance method (e.g., File::image()->max(1)->types(['jpg']) would lose the max(1) constraint). The types() method was static, so calling it on an instance created a new File object, dropping all previously configured rules.

Now works correctly both as a static factory (File::types('png')) and as a chainable instance method (File::image()->max(1)->types(['jpg'])).

Prior work

#59247 by @AnnoyingTechnology took a similar approach to fix this issue but was closed due to timing (13.x release day). This PR builds on that work.

Test plan

  • Existing 23 File validation tests still pass
  • New test verifies max() constraint is preserved when types() is called after it
  • New test verifies static factory usage still works
  • New test verifies instance chaining in both orders works

Fixes #59242

@github-actions
Copy link
Copy Markdown

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

JoshSalway and others added 2 commits March 28, 2026 23:42
The types() method was declared as static, which meant calling it on an
existing File instance (e.g. File::image()->max(1)->types(['jpg']))
would silently create a new instance, discarding all prior configuration
like max(), min(), etc.

This changes types() to work both as a static factory method and as a
chainable instance method by leveraging __call and __callStatic magic
methods. The underlying logic is moved to setTypes().

Fixes laravel#59242

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Verifies that calling types() on an existing File instance preserves
prior configuration (e.g. max()) instead of creating a new instance.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

File::types() silently discards prior chain configuration when called as instance method

1 participant