Introduction | laravel-medialibrary | Spatie

 SPATIE

  Laravel Media Library
========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-medialibrary](https://spatie.be/docs/laravel-medialibrary/v3)  Introduction

 Version   v11   v10   v9   v8   v7   v6   v5   v4   v3

 Other versions for crawler [v11](https://spatie.be/docs/laravel-medialibrary/v11) [v10](https://spatie.be/docs/laravel-medialibrary/v10) [v9](https://spatie.be/docs/laravel-medialibrary/v9) [v8](https://spatie.be/docs/laravel-medialibrary/v8) [v7](https://spatie.be/docs/laravel-medialibrary/v7) [v6](https://spatie.be/docs/laravel-medialibrary/v6) [v5](https://spatie.be/docs/laravel-medialibrary/v5) [v4](https://spatie.be/docs/laravel-medialibrary/v4) [v3](https://spatie.be/docs/laravel-medialibrary/v3)

- [ Introduction ](https://spatie.be/docs/laravel-medialibrary/v3/introduction)
- [ Postcardware ](https://spatie.be/docs/laravel-medialibrary/v3/postcardware)
- [ Requirements ](https://spatie.be/docs/laravel-medialibrary/v3/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-medialibrary/v3/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-medialibrary/v3/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-medialibrary/v3/changelog)

Basic usage
-----------

- [ Preparing your model ](https://spatie.be/docs/laravel-medialibrary/v3/basic-usage/preparing-your-model)
- [ Associating files ](https://spatie.be/docs/laravel-medialibrary/v3/basic-usage/associating-files)
- [ Retrieving media ](https://spatie.be/docs/laravel-medialibrary/v3/basic-usage/retrieving-media)
- [ Working with collections ](https://spatie.be/docs/laravel-medialibrary/v3/basic-usage/working-with-collections)

Converting images
-----------------

- [ Defining conversions ](https://spatie.be/docs/laravel-medialibrary/v3/converting-images/defining-conversions)
- [ Retrieving converted images ](https://spatie.be/docs/laravel-medialibrary/v3/converting-images/retrieving-converted-images)
- [ Regenerating images ](https://spatie.be/docs/laravel-medialibrary/v3/converting-images/regenerating-images)

Advanced usage
--------------

- [ Working with multiple filesystems ](https://spatie.be/docs/laravel-medialibrary/v3/advanced-usage/working-with-multiple-filesystems)
- [ Storing media specific manipulations ](https://spatie.be/docs/laravel-medialibrary/v3/advanced-usage/storing-media-specific-manipulations)
- [ Using your own model ](https://spatie.be/docs/laravel-medialibrary/v3/advanced-usage/using-your-own-model)
- [ Using a custom directory structure ](https://spatie.be/docs/laravel-medialibrary/v3/advanced-usage/using-a-custom-directory-structure)
- [ Consuming events ](https://spatie.be/docs/laravel-medialibrary/v3/advanced-usage/consuming-events)
- [ Generating custom urls ](https://spatie.be/docs/laravel-medialibrary/v3/advanced-usage/generating-custom-urls)
- [ Adding custom properties ](https://spatie.be/docs/laravel-medialibrary/v3/advanced-usage/adding-custom-properties)

API
---

- [ Adding files ](https://spatie.be/docs/laravel-medialibrary/v3/api/adding-files)
- [ Defining conversions ](https://spatie.be/docs/laravel-medialibrary/v3/api/defining-conversions)

      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 Media Library
=======================

Associate files with Eloquent models
------------------------------------

 A free package that associates files to Eloquent models, generates thumbnails and responsive images, and manages media across file systems.

 [    Repository ](https://github.com/spatie/laravel-medialibrary)

 [    Open Issues ](https://github.com/spatie/laravel-medialibrary/issues)

    36,865,827

    6,100

Introduction
------------

###  On this page

1. [ We have badges! ](#content-we-have-badges)

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](http://laravel.com/docs/5.1/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](/laravel-medialibrary/v3/converting-images/defining-conversions/), they're easily accessible:

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

We have badges!
---------------------------------------------------------------------------------------------------

 [![Latest Version](https://img.shields.io/github/release/spatie/laravel-medialibrary.svg?style=flat-square)](https://github.com/spatie/laravel-medialibrary/releases) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://github.com/spatie/laravel-medialibrary/blob/master/LICENSE.md) [![Build Status](https://img.shields.io/travis/spatie/laravel-medialibrary/master.svg?style=flat-square)](https://travis-ci.org/spatie/laravel-medialibrary) [![SensioLabsInsight](https://img.shields.io/sensiolabs/i/27cf455a-0555-4bcf-abae-16b5f7860d09.svg?style=flat-square)](https://insight.sensiolabs.com/projects/27cf455a-0555-4bcf-abae-16b5f7860d09) [![Quality Score](https://img.shields.io/scrutinizer/g/spatie/laravel-medialibrary.svg?style=flat-square)](https://scrutinizer-ci.com/g/spatie/laravel-medialibrary) [![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-medialibrary.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-medialibrary)
