Skip to content

Plugin options ​

Register the plugin on each panel that should have a library. Every method returns the plugin, so you can chain them.

php
use Hoceineel\FilamentMediaLibrary\Enums\BrowserLayout;
use Hoceineel\FilamentMediaLibrary\Enums\DuplicateStrategy;
use Hoceineel\FilamentMediaLibrary\Enums\Feature;
use Hoceineel\FilamentMediaLibrary\Enums\SortOrder;
use Hoceineel\FilamentMediaLibrary\FilamentMediaLibraryPlugin;
use Filament\Forms\Components\TextInput;

public function panel(Panel $panel): Panel
{
    return $panel
        ->id('admin')
        ->tenant(Team::class)
        ->plugin(
            FilamentMediaLibraryPlugin::make()
                ->navigationGroup('Content')
                ->navigationLabel('Assets')
                ->navigationIcon('heroicon-o-photo')
                ->navigationSort(20)
                ->navigationCountBadge()
                ->slug('assets')
                ->canAccess(fn (): bool => auth()->user()->isStaff())
                ->metadataSchema(fn (): array => [
                    TextInput::make('credit')->label('Photo credit'),
                    TextInput::make('license'),
                ])
                ->disableFeatures(Feature::UrlImport, Feature::AltText)
                ->defaultLayout(BrowserLayout::List)
                ->defaultSort(SortOrder::Newest)
                ->perPage(60)
                ->tileSize(200)
                ->acceptedFileTypes(['image/*', 'application/pdf'])
                ->maxFileSize(20 * 1024)
                ->duplicates(DuplicateStrategy::UseExisting),
        );
}

Fluent options apply to the panel they are registered on. They are copied into config('filament-media-library.*') when the panel boots, so they win over the config file. Outside panels no plugin runs: set the same values in the config file.

Static helpers ​

MethodReturns
FilamentMediaLibraryPlugin::make()A new plugin instance.
FilamentMediaLibraryPlugin::get()The plugin registered on the current panel.
FilamentMediaLibraryPlugin::isRegistered()true when the current panel has the plugin.

Page and navigation ​

MethodPurpose
page(string $page)Use your own page class. It must extend MediaLibraryPage.
withoutPage(bool|Closure $condition = true)Do not register the library page. Use the picker only.
registerNavigation(bool|Closure $condition = true)Show or hide the navigation item.
navigationGroup(string|Closure|null $group)Navigation group.
navigationLabel(string|Closure|null $label)Label. Defaults to the navigation_label translation.
navigationIcon(string|BackedEnum|Closure|null $icon)Icon.
navigationSort(int|Closure|null $sort)Sort position.
navigationCountBadge(bool|Closure $condition = true)Show the file count as a badge.
slug(?string $slug)Page URL slug. Defaults to media-library.

Tenancy ​

MethodPurpose
tenancy(bool $condition = true, bool $strict = true)Scope the library per tenant. On by default when the panel uses tenancy. With strict, a request without a tenant sees nothing.
resolveTenantUsing(TenantResolver|Closure|string $resolver)Resolve the tenant yourself. Panels with tenancy use FilamentTenantResolver unless you set one.

See Multi-tenancy.

Inspector metadata ​

metadataSchema(?Closure $schema) adds fields to the inspector. Return an array of Filament form components. Values are stored in the item's custom_properties.

php
->metadataSchema(fn (): array => [
    TextInput::make('credit'),
])

Access ​

canAccess(bool|Closure $condition) hides the page and its navigation item and returns 403 when the condition is false. It does not replace the policies. See Authorization.

Features ​

Three methods control the Feature flags:

MethodBehaviour
features(array $features)Keep only the listed features and switch every other one off.
enableFeatures(Feature ...$features)Switch the listed features on.
disableFeatures(Feature ...$features)Switch the listed features off.
php
FilamentMediaLibraryPlugin::make()->features([Feature::Folders, Feature::Tags, Feature::Download]);

The Hoceineel\FilamentMediaLibrary\Enums\Feature enum has 17 cases:

CaseValueSwitching it off removes
Feature::FoldersfoldersThe folder tree, folder breadcrumbs, new, rename, move and delete folder actions, and the folder field in the inspector. Everything lists at one level.
Feature::TagstagsThe tag filter, tag field in the inspector and the bulk tag action.
Feature::FavoritesfavoritesThe favorite toggle and the Favorites view.
Feature::TrashtrashThe trash. Deleting removes files for good.
Feature::PrivateMediaprivate_mediaThe private visibility option for files and folders.
Feature::VersionsversionsVersion history and the restore action.
Feature::ImageEditorimage_editorThe crop, rotate and flip editor.
Feature::FocalPointfocal_pointSetting the focal point.
Feature::UrlImporturl_importImport from URL.
Feature::FolderUploadfolder_uploadUploading a whole folder.
Feature::AltTextalt_textThe "Write it for me" alt text action.
Feature::DuplicateduplicateThe duplicate action.
Feature::DownloaddownloadDownload buttons, including the bulk ZIP download.
Feature::ExifexifThe camera data section in the inspector.
Feature::UsageusageThe "Used in" section and the Unused view.
Feature::SmartViewssmart_viewsThe Recent, Favorites, Mine and Unused views. All files and Trash stay.
Feature::KeyboardShortcutskeyboard_shortcutsKeyboard shortcuts. See Keyboard.

Defaults ​

MethodConfig keyNotes
defaultLayout(BrowserLayout $layout)browser.default_layoutBrowserLayout::Grid or BrowserLayout::List.
defaultSort(SortOrder $sort)browser.default_sortNewest, Oldest, NameAsc, NameDesc, Largest, Smallest.
perPage(int $perPage)browser.per_pageItems per page.
tileSize(int $pixels)browser.tile_sizeClamped between 120 and 280.
acceptedFileTypes(array $mimeTypes)upload.accepted_mime_typesWildcards such as image/* work.
maxFileSize(int $kilobytes)upload.max_file_sizeIn kilobytes.
duplicates(DuplicateStrategy $strategy)upload.duplicatesAsk, Allow or UseExisting.

A MediaPicker field has its own options for one field.

Commercial licence. One licence per production project. Terms · Privacy · Refunds