Skip to content

Conversation

@godismyjudge95
Copy link
Contributor

We have a number of computed properties for a specific collection and our AppServiceProvider is getting rather long with all the computed properties.

This PR helps solve this by allowing for an associative array to be passed as the 2nd parameter:

Collection::computed('properties', [
  'pdf_url' => fn ($entry, $value) => route('properties.pdf', $entry->id()),
  'deletion_date' => fn ($entry, $value) => $this->generateDeletionDate($entry),
]);

Let me know if you'd like me to add tests

@godismyjudge95 godismyjudge95 changed the title [5x] Allow passing computed fields via an associative array [5.x] Allow passing computed fields via an associative array Mar 4, 2025
@duncanmcclean
Copy link
Member

Let me know if you'd like me to add tests

If you can, that would be great!

We have existing tests for computed values in UserContractTests and EntryTest.

@jasonvarga jasonvarga merged commit 38a6099 into statamic:5.x Mar 17, 2025
24 checks passed
@godismyjudge95 godismyjudge95 deleted the patch-1 branch March 17, 2025 20:32
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.

3 participants