Download the PHP package backpack/medialibrary-uploaders without Composer
On this page you can find all versions of the php package backpack/medialibrary-uploaders. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download backpack/medialibrary-uploaders
More information about backpack/medialibrary-uploaders
Files in backpack/medialibrary-uploaders
Package medialibrary-uploaders
Short Description Helper functions to save files with spatie media library
License MIT
Homepage https://github.com/backpack/medialibrary-uploaders
Informations about the package medialibrary-uploaders
Spatie Media Library Uploaders for Backpack CRUD fields & columns
If you project uses both Spatie Media Library and Backpack for Laravel, this add-on provides the ability for:
- Backpack fields to easily store uploaded files as media (by using Spatie Media Library);
- Backpack columns to easily retrieve uploaded files as media;
More exactly, it provides the ->withMedia()
helper, that will handle the file upload and retrieval using Backpack Uploaders. You'll love how simple it makes uploads!
Requirements
Install and use spatie/laravel-medialibrary
v10. If you haven't already, please make sure you've installed spatie/laravel-medialibrary
and followed all installation steps in their docs:
Then prepare your Models to use spatie/laravel-medialibrary
, by adding the InteractsWithMedia
trait to your model and implement the HasMedia
interface like explained on Media Library Documentation.
Installation
Just require this package using Composer, that's it:
Usage
On any field where you upload a file (eg. upload
, upload_multiple
, image
or dropzone
), add withMedia()
to your field definition, in order to tell Backpack to store those uploaded files using Spatie's Laravel MediaLibrary. For example:
Advanced Use
Overriding the defaults
Backpack sets up some handy defaults for you when handling the media. But it also provides you a way to customize the bits you need from Spatie Media Library. You can pass a configuration array to ->withMedia([])
or 'withMedia' => []
to override the defaults Backpack has set.
Customizing the saving process (adding thumbnails, responsive images etc)
Inside the same configuration array mentioned above, you can use the whenSaving
closure to customize the saving process. This closure will be called in THE MIDDLE of configuring the media collection. So AFTER calling the initializer function, but BEFORE calling toMediaCollection(). Do what you want to the $spatieMedia object, using Spatie's documented methods, then return
it back to Backpack to call the termination method. Sounds good?
NOTE: Some methods will be called automatically by Backpack; You shoudn't call them inside the closure used for configuration: toMediaCollection()
, setName()
, usingName()
, setOrder()
, toMediaCollectionFromRemote()
and toMediaLibrary()
. They will throw an error if you manually try to call them in the closure.
Defining media collection in the model
You can also have the collection configured in your model as explained in Spatie Documentation, in that case, you just need to pass the collection
configuration key. But you are still able to configure all the other options including the whenSaving
callback.
Working with Conversions
Sometimes you will want to create conversions for your images, like thumbnails etc. In case you want to display some conversions instead of the original image on the field you should define displayConversions => 'conversion_name'
or displayConversions => ['higher_priority_conversion', 'second_priority_conversion']
.
In the end, if none of the conversions are ready yet (maybe they are still queued), we will display the original file as a fallback.
Custom properties
You can normally assign custom properties to your media with ->withCustomProperties([])
as stated in spatie documentation, but please be advise that name
, repeatableContainerName
and repeatableRow
are reserved keywords and Backpack values will always overwrite yours.
Change log
Changes are documented here on Github. Please see the Releases tab.
Testing
Contributing
Please see contributing.md for a todolist and howtos.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Pedro Martins - author & architect
- Cristian Tabacitu - reviewer
- Backpack for Laravel - sponsor
- All Contributors
License
This project was released under MIT, so you can install it on top of any Backpack & Laravel project. Please see the license file for more information.