Is there a simple way to limit the number of images a model can hold in a given collection?
For example, my Business model has one logo, which I have used ->single() for, and up to 3 banner images. I would like to limit it so they cannot have more than 3, and any additional uploads would replace older ones.
I'd accept a pull request that adds a onlyKeepLatest($int) function on MediaCollection. When adding a new item to the collection only the latest $int number of media models in it are kept, the rest is deleted. The PR should have updated test and updated docs. The singleFile method should, under the hood, call onlyKeepLatests(1).
Working on it! Got the code ready, heading over to writing the tests in a minute.
This has been added in the latest released. Thanks for the PR @joshuadegier
Most helpful comment
I'd accept a pull request that adds a
onlyKeepLatest($int)function onMediaCollection. When adding a new item to the collection only the latest$intnumber of media models in it are kept, the rest is deleted. The PR should have updated test and updated docs. ThesingleFilemethod should, under the hood, callonlyKeepLatests(1).