You are viewing the documentation for an older version of this package. You can check the version you are using with the following command:
composer show spatie/laravel-medialibrary
Laravel-medialibrary
Associate files with Eloquent models.
Medialibrary is a Laravel 5.1 package that can associate all sorts of files with Eloquent models. It provides a simple, fluent API to work with. Here's a quick example:
$newsItem = News ::find (1);
$newsItem ->addMedia ($pathToFile )->toCollection ('images ');
It can also directly handle your uploads:
$newsItem ->addMedia ($request ->file ('image '))->toCollection ('images ');
Want to store some large files on another filesystem? No problem:
$newsItem ->addMedia ($smallFile )->toCollectionOnDisk ('downloads ', 'local ');
$newsItem ->addMedia ($bigFile )->toCollectionOnDisk ('downloads ', 's3 ');
The storage of the files is handled by Laravel's Filesystem , so you can plug in any compatible filesystem.
The package can also generate derived images such as thumbnails for images and pdf's. Once you've set up your model , they're easily accessible:
$newsItem ->getMedia ('images ')->first ()->getUrl ('thumb ');
# # We have badges!