PHPackages                             aqjw/nova-medialibrary-field - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. aqjw/nova-medialibrary-field

ActiveLibrary[File &amp; Storage](/categories/file-storage)

aqjw/nova-medialibrary-field
============================

Laravel Nova field for managing the Spatie media library.

3.4.2(3y ago)1281MITPHPPHP ^7.4|^8.0|^8.1

Since Dec 22Pushed 3y agoCompare

[ Source](https://github.com/aqjw/nova-medialibrary-field)[ Packagist](https://packagist.org/packages/aqjw/nova-medialibrary-field)[ Docs](https://github.com/aqjw/medialibrary-field)[ RSS](/packages/aqjw-nova-medialibrary-field/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (5)Versions (72)Used By (0)

Nova Medialibrary
=================

[](#nova-medialibrary)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b7bd7bfbace16d036b8e8f3642f4b3e38b92f354835b46da076663d322defc02/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61716a772f6e6f76612d6d656469616c6962726172792d6669656c642e7376673f7374796c653d666c61742d737175617265)](https://github.com/aqjw/medialibrary-field/releases)[![Total Downloads](https://camo.githubusercontent.com/6f6afca6a807a071dae84c2ac01b63637927734d52836de7f1e5f2e64fccd939/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61716a772f6e6f76612d6d656469616c6962726172792d6669656c642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aqjw/nova-medialibrary-field)

Laravel Nova field for managing the Spatie media library.

This is the documentation for v2 and v3. For v1 follow this [link](https://github.com/aqjw/medialibrary-field/tree/1.2.2)

Features:

- add media on update/create views
- add existing media
- crop media
- sort media
- display on the index view

Table of Contents
-----------------

[](#table-of-contents)

- [Screenshots](#screenshots)
- [Installation](#installation)
- [Usage](#usage)
    - [Methods](#methods)
        - [Attribute](#attribute)
        - [Fields](#fields)
        - [AttachUsing](#attachusing)
        - [ResolveMediaUsing](#resolvemediausing)
        - [AttachExisting](#attachexisting)
        - [MediaOnIndex](#mediaonindex)
        - [DownloadUsing](#downloadusing)
        - [PreviewUsing](#previewusing)
        - [Tooltip](#tooltip)
        - [Title](#title)
        - [CopyAs](#copyAs)
        - [Croppable](#croppable)
        - [Single](#single)
        - [Accept](#accept)
        - [MaxSizeInBytes](#maxsizeinbytes)
        - [AttachOnDetails](#attachondetails)
        - [AttachRules](#attachrules)
        - [Autouploading](#autouploading)
    - [Preview Customization](#preview-customization)
    - [Validation](#validation)
    - [Sorting](#sorting)
    - [Authorization Gates 'view', 'update' and 'delete'](#authorization-gates-view-update-and-delete)
- [Translations](#translations)
- [Changelog](#changelog)
- [Alternatives](#alternatives)
- [License](#license)

Screenshots
-----------

[](#screenshots)

[![index view](https://raw.githubusercontent.com/aqjw/medialibrary-field/master/docs/index.png)](https://raw.githubusercontent.com/aqjw/medialibrary-field/master/docs/index.png)[![create view](https://raw.githubusercontent.com/aqjw/medialibrary-field/master/docs/create.png)](https://raw.githubusercontent.com/aqjw/medialibrary-field/master/docs/create.png)[![details view](https://raw.githubusercontent.com/aqjw/medialibrary-field/master/docs/details.png)](https://raw.githubusercontent.com/aqjw/medialibrary-field/master/docs/details.png)[![update view](https://raw.githubusercontent.com/aqjw/medialibrary-field/master/docs/update.png)](https://raw.githubusercontent.com/aqjw/medialibrary-field/master/docs/update.png)[![media actions](https://raw.githubusercontent.com/aqjw/medialibrary-field/master/docs/actions.png)](https://raw.githubusercontent.com/aqjw/medialibrary-field/master/docs/actions.png)[![media crop dialog](https://raw.githubusercontent.com/aqjw/medialibrary-field/master/docs/crop-dialog.png)](https://raw.githubusercontent.com/aqjw/medialibrary-field/master/docs/crop-dialog.png)[![media details dialog](https://raw.githubusercontent.com/aqjw/medialibrary-field/master/docs/media-details-dialog.png)](https://raw.githubusercontent.com/aqjw/medialibrary-field/master/docs/media-details-dialog.png)[![existing media dialog](https://raw.githubusercontent.com/aqjw/medialibrary-field/master/docs/existing-media-dialog.png)](https://raw.githubusercontent.com/aqjw/medialibrary-field/master/docs/existing-media-dialog.png)

Installation
------------

[](#installation)

This package can be installed via command:

```
composer require aqjw/nova-medialibrary-field
```

Usage
-----

[](#usage)

```
Medialibrary::make($name, $collectionName = '', $diskName = '', $attribute = null),
```

### Methods

[](#methods)

#### Attribute

[](#attribute)

Sometimes you may need to use the same field label (duplicated sections, etc). The attribute must be unique. In this case you can change the default behaviour using the `attribute()` method.

```
Medialibrary::make('name', 'collection name', 'disk name', 'custom_attribute');
// or
Medialibrary::make('name', 'collection name', 'disk name')->attribute('custom_attribute');
```

#### Fields

[](#fields)

Define custom fields for media. [MediaFields](src/Fields/Support/MediaFields.php) is used by default.

```
Medialibrary::make('Media')->fields(function () {
    return [
        Text::make('File Name', 'file_name')
            ->rules('required', 'min:2'),

        Text::make('Tooltip', 'custom_properties->tooltip')
            ->rules('required', 'min:2'),

        GeneratedConversions::make('Conversions')
            ->withTooltips(),
    ];
});
```

#### ResolveMediaUsing

[](#resolvemediausing)

```
Medialibrary::make('Media')->resolveMediaUsing(function (HasMedia $model, string $collectionName) {
    return $model->getMedia($collectionName);
});
```

#### AttachUsing

[](#attachusing)

Called inside [AttachController](src/Http/Controllers/AttachController.php#L32). [AttachCallback](src/Fields/Support/AttachCallback.php) is used by default. It accepts `$fieldUuid` which is used when a resource is not created. If you want to attach media on the create view, you should keep [these lines](src/Fields/Support/AttachCallback.php#L20-L22) in your callback.

```
Medialibrary::make('Media')
    ->attachUsing(function (HasMedia $model, UploadedFile $file, string $collectionName, string $diskName, string $fieldUuid) {
        if ($model instanceof TransientModel) {
            $collectionName = $fieldUuid;
        }

        $fileAdder = $model->addMedia($file);

        // do something

        $fileAdder->toMediaCollection($collectionName, $diskName);
    });
```

#### AttachExisting

[](#attachexisting)

Allow attaching existing media.

```
Medialibrary::make('Media')->attachExisting(); // display all media
Medialibrary::make('Media')->attachExisting('collectionName'); // display media from a specific collection
Medialibrary::make('Media')->attachExisting(function (Builder $query, Request $request, HasMedia $model) {
    $query->where(...);
});
```

#### MediaOnIndex

[](#mediaonindex)

Display media on index

```
Medialibrary::make('Media')->mediaOnIndex(1);
Medialibrary::make('Media')->mediaOnIndex(function (HasMedia $resource, string $collectionName) {
    return $resource->media()->where('collection_name', $collectionName)->limit(5)->get();
});
```

#### DownloadUsing

[](#downloadusing)

```
Medialibrary::make('Media')->downloadUsing('conversionName');
Medialibrary::make('Media')->downloadUsing(function (Media $media) {
    return $media->getFullUrl();
});
```

#### PreviewUsing

[](#previewusing)

```
Medialibrary::make('Media')->previewUsing('conversionName');
Medialibrary::make('Media')->previewUsing(function (Media $media) {
    return $media->getFullUrl('preview');
});
```

#### Tooltip

[](#tooltip)

```
Medialibrary::make('Media')->tooltip('file_name');
Medialibrary::make('Media')->tooltip(function (Media $media) {
    return $media->getCustomProperty('tooltip');
});
```

#### Title

[](#title)

```
Medialibrary::make('Media')->title('name');
Medialibrary::make('Media')->title(function (Media $media) {
    return $media->name;
});
```

#### CopyAs

[](#copyas)

```
Medialibrary::make('Media')->copyAs('Url', function (Media $media) {
    return $media->getFullUrl();
});

Medialibrary::make('Media')->copyAs('Html', function (Media $media) {
    return $media->img();
}, 'custom-icon');

// You can hide default "Copy Url"
Medialibrary::make('Media')->hideCopyUrlAction();
```

#### Croppable

[](#croppable)

```
Medialibrary::make('Media')->croppable('conversionName');
Medialibrary::make('Media')->croppable('conversionName', ['viewMode' => 3]);
Medialibrary::make('Media')->croppable('conversionName', [
    'rotatable' => false,
    'zoomable' => false,
    'cropBoxResizable' => false,
]);
Medialibrary::make('Media')->croppable('conversionName', function (Media $media) {
    return $media->getCustomProperty('croppable') ? ['viewMode' => 3] : null;
});
```

> {note} If your media in different collection, make sure pass your collectionName to `performOnCollections`

```
$this->addMediaConversion('conversionName')->performOnCollections('collectionName')
```

#### Single

[](#single)

```
Medialibrary::make('Media')->single();
```

#### Accept

[](#accept)

```
Medialibrary::make('Media')->accept('image/*');
```

#### MaxSizeInBytes

[](#maxsizeinbytes)

```
Medialibrary::make('Media')->maxSizeInBytes(1024 * 1024);
```

#### AttachOnDetails

[](#attachondetails)

Allows attaching files on the details view.

```
Medialibrary::make('Media')->attachOnDetails();
```

#### AttachRules

[](#attachrules)

```
Medialibrary::make('Media')->attachRules('image', 'dimensions:min_width=500,min_height=500');
```

#### Autouploading

[](#autouploading)

```
Medialibrary::make('Media')->autouploading();
```

#### Preview Customization

[](#preview-customization)

```
Medialibrary::make('Media')->withMeta([
    'indexPreviewClassList' => 'rounded w-8 h-8 ml-2',
    'detailsPreviewClassList' => 'w-32 h-24 rounded-b',
]);
```

### Validation

[](#validation)

```
Medialibrary::make('Media')
    ->rules('array', 'required') // applied to the media collection
    ->creationRules('min:2') // applied to the media collection
    ->updateRules('max:4') // applied to the media collection
    ->attachRules('image', 'dimensions:min_width=500,min_height=500'); // applied to media
```

### Sorting

[](#sorting)

```
Medialibrary::make('Media')->sortable();
```

### Authorization Gates 'view', 'update' and 'delete'

[](#authorization-gates-view-update-and-delete)

To view, update and delete uploaded media, you need to setup some gates. You can use the store and replace callbacks to store additional information to the custom\_properties. The additional information can be used inside the gates for authorization.

```
Gate::define('view', function ($user, $media) {
    return true; // view granted
});

Gate::define('update', function ($user, $media) {
    return true; // update granted
});

Gate::define('delete', function ($user, $media) {
    return true; // deletion granted
});
```

You can also use the policy.

```
class MediaPolicy
{
    public function view(User $user, Media $media): bool
    {
        return true;
    }

    public function update(User $user, Media $media): bool
    {
        return true;
    }

    public function delete(User $user, Media $media): bool
    {
        return true;
    }
}

class AuthServiceProvider extends ServiceProvider
{
    protected $policies = [
        Media::class => MediaPolicy::class,
    ];

    //...
}
```

Translations
------------

[](#translations)

- [en](resources/lang/en.json)
- [fr](resources/lang/fr.json)
- [pt-BR](resources/lang/pt-BR.json)
- [ru](resources/lang/ru.json)
- [tr](resources/lang/tr.json)
- [uk](resources/lang/uk.json)
- [zh-CN](resources/lang/zh-CN.json)

Changelog
---------

[](#changelog)

Please see the [CHANGELOG](CHANGELOG.md) for more information about the most recent changed.

Alternatives
------------

[](#alternatives)

-

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity85

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 56% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~24 days

Recently: every ~137 days

Total

67

Last Release

1136d ago

Major Versions

2.0.14 → 3.0.32020-04-14

2.0.16 → 3.0.42020-04-27

2.0.18 → 3.0.52020-04-27

2.0.20 → 3.0.72020-05-17

2.1.2 → 3.1.12020-09-10

PHP version history (5 changes)1.0.0PHP &gt;=7.1.0

2.0PHP ^7.3

3.0.0PHP ^7.4

3.2.6PHP ^7.4|^8.0

3.3PHP ^7.4|^8.0|^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/3bbc50eee573168342cf8eaa53bcc09048939b7dc4bb79187133c919ce6e1e8b?d=identicon)[aqjw](/maintainers/aqjw)

---

Top Contributors

[![dmitrybubyakin](https://avatars.githubusercontent.com/u/11477505?v=4)](https://github.com/dmitrybubyakin "dmitrybubyakin (136 commits)")[![repl6669](https://avatars.githubusercontent.com/u/5587309?v=4)](https://github.com/repl6669 "repl6669 (57 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (10 commits)")[![crossatko](https://avatars.githubusercontent.com/u/3613973?v=4)](https://github.com/crossatko "crossatko (5 commits)")[![kaysersoze](https://avatars.githubusercontent.com/u/735028?v=4)](https://github.com/kaysersoze "kaysersoze (4 commits)")[![aqjw](https://avatars.githubusercontent.com/u/13101908?v=4)](https://github.com/aqjw "aqjw (4 commits)")[![robin-dongbin](https://avatars.githubusercontent.com/u/24680921?v=4)](https://github.com/robin-dongbin "robin-dongbin (3 commits)")[![leopoletto](https://avatars.githubusercontent.com/u/1036401?v=4)](https://github.com/leopoletto "leopoletto (3 commits)")[![aemaddin](https://avatars.githubusercontent.com/u/11630742?v=4)](https://github.com/aemaddin "aemaddin (2 commits)")[![ahmetbedir](https://avatars.githubusercontent.com/u/10426366?v=4)](https://github.com/ahmetbedir "ahmetbedir (2 commits)")[![authanram](https://avatars.githubusercontent.com/u/1874088?v=4)](https://github.com/authanram "authanram (2 commits)")[![den1n](https://avatars.githubusercontent.com/u/25498109?v=4)](https://github.com/den1n "den1n (2 commits)")[![monaye](https://avatars.githubusercontent.com/u/1147313?v=4)](https://github.com/monaye "monaye (2 commits)")[![nasrulhazim](https://avatars.githubusercontent.com/u/10341422?v=4)](https://github.com/nasrulhazim "nasrulhazim (2 commits)")[![nonovd](https://avatars.githubusercontent.com/u/12936673?v=4)](https://github.com/nonovd "nonovd (2 commits)")[![filipzlamala](https://avatars.githubusercontent.com/u/6141275?v=4)](https://github.com/filipzlamala "filipzlamala (1 commits)")[![bernhardh](https://avatars.githubusercontent.com/u/642292?v=4)](https://github.com/bernhardh "bernhardh (1 commits)")[![thecaliskan](https://avatars.githubusercontent.com/u/13554944?v=4)](https://github.com/thecaliskan "thecaliskan (1 commits)")[![priithansen](https://avatars.githubusercontent.com/u/1476082?v=4)](https://github.com/priithansen "priithansen (1 commits)")[![Grayda](https://avatars.githubusercontent.com/u/4891563?v=4)](https://github.com/Grayda "Grayda (1 commits)")

---

Tags

laravelnovamedialibrary

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/aqjw-nova-medialibrary-field/health.svg)

```
[![Health](https://phpackages.com/badges/aqjw-nova-medialibrary-field/health.svg)](https://phpackages.com/packages/aqjw-nova-medialibrary-field)
```

###  Alternatives

[dmitrybubyakin/nova-medialibrary-field

Laravel Nova field for managing the Spatie media library.

270654.1k2](/packages/dmitrybubyakin-nova-medialibrary-field)[infinety-es/nova-filemanager

Filemanager tool for Laravel Nova

219369.3k4](/packages/infinety-es-nova-filemanager)[oneduo/nova-file-manager

A handy file manager tool for Laravel Nova

159399.9k2](/packages/oneduo-nova-file-manager)[digital-creative/nova-filepond

A Nova field for uploading File, Image and Video using filepond.

5570.9k1](/packages/digital-creative-nova-filepond)[bbs-lab/nova-file-manager

A handy file manager tool for Laravel Nova

1598.1k](/packages/bbs-lab-nova-file-manager)[slimani/filament-media-manager

A media manager plugin for Filament.

126.9k](/packages/slimani-filament-media-manager)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
