Our Blade components are meant to be used in a regular HTML forms. If you want to use Media Library Pro within your own Livewire components, read this page on handling uploads with Livewire.
The x-media-library-attachment will take care of the upload. Under the hood the upload is processed by
a Livewire component.
After a file has been uploaded it will be stored as a temporary upload. In case there are validation errors when
submitting the form, the x-media-library-attachment will display the temporary upload when you get redirected back to
the form. There's no need for the user to upload the file again.
In the controller handling the form submission you should validate the temporary upload and transfer it to an Eloquent
model. You can read more on that on this page.
After files have been uploaded, they will be stored as a temporary uploads.
In the controller handling the form submission you should validate the temporary upload and transfer it to an Eloquent
model. You can read more on that on this page.
Here's a video where multiple uploads are being demoed:
The upload can be validated before the form is submitted by adding a rules attribute. In the value of the attribute
you can use any of Laravel's available validation rules that are applicable to file uploads.
Here's an example where we only accept png and jpg files that are 1MB or less.
This validation only applies on the creation of the temporary uploads. You should also perform validation
when processing the upload on the server.
##Administer the contents of a media library collection
You can manage the entire contents of a media library collection with x-media-library-collection component. This
component is intended to use in admin sections.
Here is an example where we are going to administer an images collection of a $blogPost model. We assume that you
already prepared the model to handle uploads.
This component will display the contents of the entire collection. Files can be added, removed, updated and reordered.
New files will be uploaded as temporary uploads.
The value you pass in name of the component will be use as the key name in which the component will send the state of
the collection to the backend. In the controller handling the form submission you should validate the new contents of
the collection and sync it with the collection of the eloquent model. You can read more on that on this page.
Like the x-media-library-attachment component, the x-media-library-collection accepts max-items and rules props.
In this example, the collection will be allowed to hold png and jpg files that are smaller than 1 MB.
Media library supports custom properties to be saved on a media item. By
default, the x-media-library-collection component doesn't show the custom properties. To add them you should create a
blade view that will be used to display all form elements on a row in the component.
In this example we're going to add a custom property form field called extra_field.
Under the hood, the attachment and collection components use Livewire to perform uploads. Currently, Livewire does not support uploading multiple files to S3. That's why only the attachment component can be used to upload files to S3.
To get started with upload files to s3, make sure to follow Livewire's instructions on how to upload directly to S3.
Next, make sure you configured the media disk that uses the S3 driver.
With that configuration in place, the attachment component will now upload directly to S3.