[9.x] Add ->set()
method to factory
#41890
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Lately I've been writing unit-tests for the models of an application that did not have many tests yet. In that application many scopes were used.
I noticed that I was often creating models like this, where you just need to make one little change every time:
I figured out that the tests would look a lot cleaner if we could just get rid of those single-item arrays, so I came up with a small method called
->set()
. This method is in my eyes easier and more expressive than->create(['foo' => 'bar'])
, because it is immediately clear that we're setting only a single property here.Another option would be to name the method
->put()
, in line with the similar collection method (but personally I prefer->set()
).