Skip to content

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

Closed
JoshSalway wants to merge 2 commits into12.xfrom
fix/file-types-static-method
Closed

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

Conversation

@JoshSalway
Copy link
Copy Markdown
Owner

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']))

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 laravel#59242

🤖 Generated with Claude Code

JoshSalway and others added 2 commits March 19, 2026 05:11
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>
@JoshSalway
Copy link
Copy Markdown
Owner Author

Moved upstream → laravel#59324

@JoshSalway JoshSalway closed this Mar 22, 2026
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