PHPackages                             achrafbardan/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. achrafbardan/nova-medialibrary-field

ActiveLibrary

achrafbardan/nova-medialibrary-field
====================================

Laravel Nova field for managing the Spatie media library.

3.2.14(4y ago)099MITPHPPHP ^7.4|^8.0|^8.1

Since Dec 22Pushed 4y agoCompare

[ Source](https://github.com/AchrafBardan/nova-medialibrary-field)[ Packagist](https://packagist.org/packages/achrafbardan/nova-medialibrary-field)[ Docs](https://github.com/dmitrybubyakin/nova-medialibrary-field)[ RSS](/packages/achrafbardan-nova-medialibrary-field/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (5)Versions (67)Used By (0)

Medialibrary Field for Laravel Nova
===================================

[](#medialibrary-field-for-laravel-nova)

[![Latest Version on Packagist](https://camo.githubusercontent.com/44350496ec1dc36d4fc9b845f1a43c7a80a61fec50dda98d37a3a352ffae296c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646d6974727962756279616b696e2f6e6f76612d6d656469616c6962726172792d6669656c642e7376673f7374796c653d666c61742d737175617265)](https://github.com/dmitrybubyakin/nova-medialibrary-field/releases)[![Total Downloads](https://camo.githubusercontent.com/9db7ffc321235cdf035017db4e985b7be33650e23be56c9f465a95e2db4cfa88/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646d6974727962756279616b696e2f6e6f76612d6d656469616c6962726172792d6669656c642e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dmitrybubyakin/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/dmitrybubyakin/nova-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/dmitrybubyakin/nova-medialibrary-field/master/docs/index.png)](https://raw.githubusercontent.com/dmitrybubyakin/nova-medialibrary-field/master/docs/index.png)[![create view](https://raw.githubusercontent.com/dmitrybubyakin/nova-medialibrary-field/master/docs/create.png)](https://raw.githubusercontent.com/dmitrybubyakin/nova-medialibrary-field/master/docs/create.png)[![details view](https://raw.githubusercontent.com/dmitrybubyakin/nova-medialibrary-field/master/docs/details.png)](https://raw.githubusercontent.com/dmitrybubyakin/nova-medialibrary-field/master/docs/details.png)[![update view](https://raw.githubusercontent.com/dmitrybubyakin/nova-medialibrary-field/master/docs/update.png)](https://raw.githubusercontent.com/dmitrybubyakin/nova-medialibrary-field/master/docs/update.png)[![media actions](https://raw.githubusercontent.com/dmitrybubyakin/nova-medialibrary-field/master/docs/actions.png)](https://raw.githubusercontent.com/dmitrybubyakin/nova-medialibrary-field/master/docs/actions.png)[![media crop dialog](https://raw.githubusercontent.com/dmitrybubyakin/nova-medialibrary-field/master/docs/crop-dialog.png)](https://raw.githubusercontent.com/dmitrybubyakin/nova-medialibrary-field/master/docs/crop-dialog.png)[![media details dialog](https://raw.githubusercontent.com/dmitrybubyakin/nova-medialibrary-field/master/docs/media-details-dialog.png)](https://raw.githubusercontent.com/dmitrybubyakin/nova-medialibrary-field/master/docs/media-details-dialog.png)[![existing media dialog](https://raw.githubusercontent.com/dmitrybubyakin/nova-medialibrary-field/master/docs/existing-media-dialog.png)](https://raw.githubusercontent.com/dmitrybubyakin/nova-medialibrary-field/master/docs/existing-media-dialog.png)

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

[](#installation)

This package can be installed via command:

```
composer require dmitrybubyakin/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

35

—

LowBetter than 79% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity84

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 76.2% 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 ~18 days

Recently: every ~48 days

Total

64

Last Release

1550d 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

v2.x-dev → 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.2.14PHP ^7.4|^8.0|^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/37a4fee54c8648eba744877a046633962519a1ea55f0e0d22ccd11d9fb75bf8a?d=identicon)[AchrafBardan](/maintainers/AchrafBardan)

---

Top Contributors

[![dmitrybubyakin](https://avatars.githubusercontent.com/u/11477505?v=4)](https://github.com/dmitrybubyakin "dmitrybubyakin (131 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (10 commits)")[![kaysersoze](https://avatars.githubusercontent.com/u/735028?v=4)](https://github.com/kaysersoze "kaysersoze (4 commits)")[![leopoletto](https://avatars.githubusercontent.com/u/1036401?v=4)](https://github.com/leopoletto "leopoletto (3 commits)")[![robin-dongbin](https://avatars.githubusercontent.com/u/24680921?v=4)](https://github.com/robin-dongbin "robin-dongbin (3 commits)")[![AchrafBardan](https://avatars.githubusercontent.com/u/72659310?v=4)](https://github.com/AchrafBardan "AchrafBardan (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)")[![MammutAlex](https://avatars.githubusercontent.com/u/10599196?v=4)](https://github.com/MammutAlex "MammutAlex (1 commits)")[![priithansen](https://avatars.githubusercontent.com/u/1476082?v=4)](https://github.com/priithansen "priithansen (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)")[![Grayda](https://avatars.githubusercontent.com/u/4891563?v=4)](https://github.com/Grayda "Grayda (1 commits)")[![filipzlamala](https://avatars.githubusercontent.com/u/6141275?v=4)](https://github.com/filipzlamala "filipzlamala (1 commits)")[![m-a-k-o](https://avatars.githubusercontent.com/u/6873535?v=4)](https://github.com/m-a-k-o "m-a-k-o (1 commits)")

---

Tags

laravelnovamedialibrary

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[dmitrybubyakin/nova-medialibrary-field

Laravel Nova field for managing the Spatie media library.

268612.7k2](/packages/dmitrybubyakin-nova-medialibrary-field)[stepanenko3/nova-command-runner

Laravel Nova tool for running Artisan and bash(shell) commands.

36983.0k](/packages/stepanenko3-nova-command-runner)[sbine/route-viewer

A Laravel Nova tool to view your registered routes.

57215.9k](/packages/sbine-route-viewer)[stepanenko3/nova-media-field

A Laravel Nova field for laravel-medilibrary.

1717.5k](/packages/stepanenko3-nova-media-field)

PHPackages © 2026

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