If you have different types of files that you want to associate,
you can put them in their own collection.
$newsItem = News::find(1);
All media in a specific collection can be retrieved like this:
A collection can have any name you want. If you don't specify a name, the file will be added to a collection named
You can clear out a specific collection by passing the name to
Also, there is a
clearMediaCollectionExcept method which can be useful if you want to remove only few or some selected media in a collection. It accepts the collection name as the first argument and the media instance or collection of media instances which should not be removed as the second argument: