Laravel Medialibrary

spatie/laravel-medialibrary image

Laravel Medialibrary stats

Downloads
15.4M
Stars
5,428
Open Issues
12
Forks
1,025

View on GitHub →

Associate files with Eloquent models

Laravel Media Library Package Summary

The Spatie Laravel Media Library package provides a robust way to associate files with Eloquent models in Laravel applications. It simplifies the management of media files by offering a fluent, intuitive API to handle file uploads, storage, and manipulation seamlessly.

Key Features

  • Easy File Association: Quickly associate files with Eloquent models using simple API methods.
  • Flexible File Handling: Directly handle file uploads from user inputs.
  • Multiple Storage Options: Supports different storage systems per collection, allowing you to store files locally or on external services like Amazon S3.
  • Image Manipulations: Automatic image and PDF manipulation when files are added to the media library, leveraging Laravel's Filesystem features.
  • Extensive Documentation: Detailed user guides and examples are available, making it easy to integrate and use the package in your projects.

Installation

Installation can be done via Composer:

composer require spatie/laravel-medialibrary

Refer to the official documentation for detailed installation and setup instructions.

Usage Examples

Associate a file with a model:

$newsItem = News::find(1);
$newsItem->addMedia($pathToFile)->toMediaCollection('images');

Handle file uploads directly from a request:

$newsItem->addMedia($request->file('image'))->toMediaCollection('images');

Store large files in different storage systems:

$newsItem->addMedia($bigFile)->toMediaCollection('downloads', 's3');

Additional Resources

  • Testing: Information on running tests using Pest and Github Actions is provided.
  • Contributing: Guidelines for contributing to the package are available.
  • Security: Instructions for reporting security vulnerabilities.

Support and Community

Spatie, the creator of this package, welcomes support via sponsorships and appreciates feedback and contributions to their open source work. Users are encouraged to send postcards as a unique way of saying thanks!

Conclusion

The Laravel Media Library package by Spatie is an essential tool for developers looking to efficiently manage media files in their Laravel applications. With its comprehensive features and supportive documentation, it ensures a smoother development experience and enhances the capabilities of Laravel projects.

For more details and to explore the full capabilities of the package, visit the official documentation.

spatie photo

We create open source, digital products and courses for the developer community

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Spatie Laravel Medialibrary Related Articles

Laravel Cyber Deals image

Laravel Cyber Deals

Read article
Laravel Black Friday Deals image

Laravel Black Friday Deals

Read article
Learn how to upload files in Laravel like a Pro image

Learn how to upload files in Laravel like a Pro

Read article
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Blastup logo

Blastup

Blastup provides social media enhancement services including buying Instagram likes, followers, and views, with features like instant delivery and a variety of packages to suit different needs.

Blastup
No Compromises logo

No Compromises

Joel and Aaron, the two seasoned devs from the No Compromises podcast, are now available to hire for your Laravel project. ⬧ Flat rate of $9500/mo. ⬧ No lengthy sales process. ⬧ No contracts. ⬧ 100% money back guarantee.

No Compromises
Tighten logo

Tighten

We help companies turn great ideas into amazing apps, products, and services.

Tighten
Statamic logo

Statamic

The drop-in ready Laravel CMS you’re been waiting for. Go full-stack or headless, flat file or database – it’s up to you.

Statamic
Celebian logo

Celebian

Celebian is a social media marketing agency specializing in helping their clients go viral on TikTok. Whether you're looking to reach a bigger audience or gain more Tiktok followers, likes, and views, they've got you covered.

Celebian