This is the documentation for
v8 but the latest version is
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
You can associate a file with a model like this:
$yourModel = YourModel::find(1);
The file will now be associated with the
YourModel instance and will be moved to the disk you've configured.
If you want to not move, but copy, the original file you can call
You can also add a remote file to the media library:
$url = 'http://medialibrary.spatie.be/assets/images/mountain.jpg';
If a file already exists on a storage disk, you can also add it to the media library:
The media library does not restrict what kinds of files may be uploaded or associated with models. If you are accepting file uploads from users, you should take steps to validate those uploads, to ensure you don't introduce security vulnerabilities into your project. Laravel has a a rule to validate uploads based on MIME type or file extension.