Adding a file to the medialibrary is easy. Just pick one of the starting methods, optionally add some of the middle methods
and finish with a finishing method. All start and middle methods are chainable.
For example:
$yourModel
->addMedia($pathToFile)
->withCustomProperties(['mime-type' => 'image/jpeg'])
->preservingOriginal()
->toMediaLibrary();
##Starting methods
##addMedia
public function addMedia($file)
##v3.8+ addMediaFromUrl
public function addMediaFromUrl($url)
##copyMedia
public function copyMedia($file)
##Middle methods
##preserveOriginal
public function preservingOriginal()
##usingName
public function usingName($name)
##setName
This is an alias for usingName
##usingFileName
public function usingFileName($fileName)
##setFileName
This is an alias for usingFileName
##withCustomProperties
public function withCustomProperties(array $customProperties)
##Finishing methods
##toMediaLibrary
public function toMediaLibrary($collectionName = 'default', $diskName = ''
##toMediaLibraryOnDisk
This is an alias for toMediaLibrary
##toCollection
This is an alias for toMediaLibrary
##toCollectionOnDisk
This is an alias for toMediaLibrary