This is the documentation for
v3 but the latest version is
v10
.
You can switch versions in the menu on the left/at the top.
Check your current version with the following command:
composer show spatie/laravel-medialibrary
When adding a file to the medialibrary you can pass an array with custom properties:
$mediaItem = $newsItem
->addMedia($pathToFile)
->withCustomProperties(['mime-type' => 'image/jpeg'])
->toMediaLibrary();
v3.3+ There are some convenience methods to work with custom properties:
$mediaItem->hasCustomProperty('mime-type'); // returns true
$mediaItem->getCustomProperty('mime-type'); // returns 'image/jpeg'
$mediaItem->hasCustomProperty('does not exists'); // returns false
$mediaItem->getCustomProperty('does not exists'); // returns null
v3.5+ You can also specify a default value when retrieving a custom property.
$mediaItem->getCustomProperty('isPublic', false);