Components
Media Library
Integrations
Upgrade guide (beta)
If you are upgrading from V3 to V4 of the Filament Media Library, please read this guide carefully as there are some breaking changes.
Please note that the V4 version is currently in beta to seek feedback. This means that some features might not be fully implemented yet or might evolve.
Upgrade Steps
Upgrade Composer version
To upgrade to Filament Media Library Pro V4, you need to update your Composer dependency. Run the following command in your terminal:
Or update your composer.json by increasing the version to ^4.0:
Also make sure to explicitly require the spatie/laravel-medialibrary dependency. As the Media Library V4 supports multiple drivers, the dependency is not included anymore by default and must be required manually.
Review custom theme
Please verify that you are using a custom theme compatible with Filament V4.
Next, open up the theme.css file for the custom theme and add the following lines:
Remove any @source imports as these are handled automatically by the plugin.
You should also add this line to any CSS files that you are using if you are planning to use the Media Library outside a Filament panel. You might need to correct the number of ../ to reach the vendor directory depending on where your CSS file is located.
Review `$plugin` methods
Next, for each panel, you need to review the methods that you are calling on the $plugin = FilamentMediaLibrary::make() object:
Next, you should also review the Media-conversions that are generated by the package. As the package now comes with an integration with Glide, which can generate images in the ideal size very effectively on-the-fly with less compute, the package does not enable any Spatie MediaLibrary conversions by default.
If you are upgrading, you will likely want to keep the conversions enabled, which you can do by opting in to conversions on $driver->conversions():
Review `MediaPicker`
Next, review the instances of the MediaPicker in your forms:
Review `MediaColumn`
Review the instances of the MediaColumn in your tables. If you are using the MediaColumn to display media from a relationship, you now need to explicitly add the ->relationship() method:
Review `MediaEntry`
Review the instances of the MediaEntry in your infolists. As using a relationship is not explicitly required anymore, you now need to explicitly add the ->relationship() method:
Alternatively, you can also use it without a relationship:
Review `spatie/laravel-media-library` config
This step is only if you were using a private disk for your Media Library. In that case, open the config/media-library.php and remove the custom url_generator line:
Remove `@mediaPickerModal`
This step is only for those who were using the Media Library in forms outside of any panel and who had the @mediaPickerModal directive in their Blade view.
In V4, the modal will now use Filament Actions, so you can remove the Blade-directive. Make sure though that you do have the default Filament Actions modals component somewhere in your layout instead:
Rename Model imports
If you are importing the MediaLibraryItem or MediaLibraryFolder models in your code, you need to update the namespace:
Review programmatic upload
This step only applies to those who are programmatically adding files to the Media Library.
Rather than calling MediaLibraryItem::addUpload(...), you will now need to instantiate the driver:
If you'd like to provide a folder to upload in:
To upload a file to the Media Library from a disk, use the fromDisk() method:
If you would need to upload images from other sources, please let me know and I can provide alternative methods on the TemporaryFileUploadData object.
Review V2 config
This step is only for those who are already using the plugin since version 2 and who have the config/filament-media-library.php published.
If you have this file, then remove the file and implement any configurations on the $plugin object instead. In V3 the plugin also no longer used the configuration file, but any values were mapped to the $plugin object. In V4, the plugin has been entirely re-built and no longer supports the V2 configuration file.
This file was not included in V3 of the Media Library, but it was still read for backwards compatibility reasons.
Review `spatie/laravel-tags` usage
This step is only for those who integrated the V3 with spatie/laravel-tags using the example code-snippets.
In V4, the Media Library has built-in support for spatie/laravel-tags and you can now enable it using the ->spatieTagsIntegration() method on the $plugin object:
The required Spatie\Tags\HasTags trait is now automatically loaded into the MediaLibraryItem model, so you no longer need to add it yourself. If you were extending the MediaLibraryItem model just to add the HasTags trait, you can now entirely remove the extended model and the $plugin->modelItem() call as the trait is now inserted automatically if you have spatie/laravel-tags installed.
Review custom pages
This step is only for those who created custom pages by extending the UploadMedia, BrowseLibrary and MediaInfo classes.
The Media Library V4 has been re-built from the ground up using Filament Schemas. The above components do therefore no longer exist and the methods have been removed.
If you were adding custom functionality to components, please review the current documentation and features of the V4 version, as many features that previously required custom code are now natively supported.
Furthermore, if you have any further customizations, reach out to support@ralphjsmit.com to get help on how to best implement these in the new version.
Review `MediaLibrary` facade
This step only applies to who are using the RalphJSmit\Filament\MediaLibrary\Facades\MediaLibrary facade in their code.
Custom conversions can now be registered using the registerConversions() method on the driver instead:
During the beta, comment out the use of the MediaLibrary facade for the remaining methods. Alternative methods will be provided during the beta period. Please reach out if this is crucial for you.
The foundation of the Media Library has been several years old. The focus of this upgrade has been on rebuilding the Media Library from the ground up, lifting it to fully adhere to modern Filament V4 coding standards and best practices. Shortly, making it ready for the next 5 years.
Furthermore, the Media Library is now running on a driver-based system, so projects don't have to use the MediaLibraryItem-based structure anymore, but can also easily run the Media Library on a (pre-existing) storage/disk, or plugging in their current Spatie Media Library-library, without requiring MediaLibraryItem. Furthermore, one can also provide custom drivers, ensuring that virtually any library can run and that legacy projects can always also easily be converted to the Media Library by just implementing a custom driver.
Finally, the Media Library has been built from the ground up using Filament Schemas and Filament Actions. This allows extreme levels of customization and flexibility.
I hope you enjoy using the new Media Library as much as I enjoyed building it! If you have any questions or feature requests, please send an e-mail to support@ralphjsmit.com.