Skip to main content
Back to packages
6,124 GitHub stars

spatie/laravel-medialibrary

View on GitHub

Description

This package can associate all sorts of files with Eloquent models. It provides a simple, fluent API to work with.

Here are some quick code examples:

$yourModel = YourModel::find(1);
$yourModel->addMedia($pathToFile)->toMediaCollection('images');

It can also directly handle your uploads:

$yourModel->addMediaFromRequest('image')->toMediaCollection('images');

Want to store some large files on another filesystem? No problem:

$yourModel->addMedia($smallFile)->toMediaCollection('downloads', 'local');
$yourModel->addMedia($bigFile)->toMediaCollection('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, videos and PDFs. Once you've set up your model, they're easily accessible:

$yourModel->getMedia('images')->first()->getUrl('thumb');

Related Content on Laravel Daily

Recent Courses on Laravel Daily

Testing in Laravel 13 For Beginners

26 lessons
1 h 41 min read

Queues in Laravel 13

18 lessons
1 h 12 min read

[FREE] Laravel 13 for Beginners: 3 Demo Projects

5 lessons
29 min

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.