Getting started
Library
Components
Integrations
Redirecting
You can deep-link to the Media Library page so that, on load, it opens directly inside a specific folder, or with a specific file selected in the file-info panel. This is useful when redirecting from another part of your app (e.g. "Manage media" buttons on a record) directly to the relevant location in the library.
The page reads two query parameters on mount:
| Parameter | Purpose |
|---|---|
folder
|
Opens the library inside the given folder. |
file
|
Opens the library inside the file's parent folder and pre-selects the file in the file-info panel. |
If a scoped folder is configured and the requested file or folder lives outside it, the page returns a 404. View authorization is also evaluated against the requested file.
Generating the URL
Use MediaLibrary::getUrl() and pass the appropriate query parameter. The value is the file's or folder's key — it can be obtained from a driver-resolved FileData via $file->getKey(), or constructed manually using the formats below.
use RalphJSmit\Filament\MediaLibrary\Filament\Pages\MediaLibrary;
// Redirect to a folder
$url = MediaLibrary::getUrl(['folder' => $folderKey]);
// Redirect to a file (opens its parent folder and selects the file)
$url = MediaLibrary::getUrl(['file' => $fileKey]);
Key formats per driver
The query value is the driver's raw key string. Each driver uses a different format:
| Driver |
folder value
|
file value
|
|---|---|---|
| Media Library Item |
media-library-folder:{id} (e.g. …:5)
|
media-library-item:{id} (e.g. …:12)
|
| Spatie Media Library |
collection:{name} (or composite virtual-folder key)
|
media:{id} (Spatie media.id)
|
| Storage/disk |
folder:{relative/path}
|
file:{relative/path/to/file.jpg}
|
For example, to open folder id = 5 with the Media Library Item driver:
MediaLibrary::getUrl(['folder' => 'media-library-folder:5']);
// {panel}/media-library?folder=media-library-folder%3A5
And to pre-select a file by path with the Storage/disk driver:
MediaLibrary::getUrl(['file' => 'file:images/photo.jpg']);
// {panel}/media-library?file=file%3Aimages%2Fphoto.jpg
The simplest way to obtain the key for an existing
FileDatais to call$file->getKey()directly — that returns the exact value to pass into the query parameter, regardless of the active driver.