---
url: /reference/commands.md
description: >-
  The four media-library Artisan commands: install, import, regenerate and
  prune, with every option and scheduling advice.
---

# Commands

## media-library:install

```bash
php artisan media-library:install
```

| Option | Purpose |
|---|---|
| `--force` | Overwrite the published config file. |

Publishes `config/filament-media-library.php`, publishes Spatie's `media-library` config and `create_media_table` migration when they are missing, offers to run `migrate`, and links `storage` for the `public` disk. It ends with a list of next steps. See [Installation](/guide/installation).

## media-library:import

```bash
php artisan media-library:import spatie --model="App\Models\Post" --collection=gallery --folder="Imported" --dry-run
php artisan media-library:import curator --update=posts.cover_id --map=curator-map.json
php artisan media-library:import directory uploads/2024 --disk=s3
```

| Argument or option | Purpose |
|---|---|
| `source` | `spatie`, `curator` or `directory`. |
| `path` | Directory source only. The directory to import, relative to the disk root. |
| `--disk=` | Directory source only. Disk to read from. Defaults to the library disk. |
| `--model=*` | Spatie only. Import media attached to these model classes. Repeatable. |
| `--collection=*` | Spatie only. Import these collections. Repeatable. |
| `--move` | Spatie only. Delete the original Spatie media after copying it. |
| `--table=curator` | Curator only. The table that holds the media rows. |
| `--update=*` | Curator only. Foreign key columns to rewrite to the new ids, as `table.column`. Repeatable. |
| `--folder=` | Put everything in this folder. It is created when missing. |
| `--map=` | Write a JSON map of old id to new library id to this file. |
| `--tenant=` | Tenant key to assign to imported records. |
| `--tenant-model=` | Tenant model class. Required with `--tenant`. |
| `--dry-run` | Count what would be imported and write nothing. Add `-v` to list each file. |

Imports are safe to repeat. Each record stores where it came from in `custom_properties.imported_from`, and files already imported are skipped. A file that fails is skipped with a warning and the run continues. The full walk-through is in [Importing existing files](/guide/importing).

## media-library:regenerate

```bash
php artisan media-library:regenerate --only=thumb --missing
```

| Option | Purpose |
|---|---|
| `--only=*` | Rebuild only these conversion names. Repeatable. |
| `--missing` | Build only conversions that do not exist yet. |

Rebuilds conversions and responsive images for every file, with a progress bar. Run it after you change the `conversions` array in [the config](/reference/configuration#conversions), or after you move files to a new disk. Conversions marked `queued` still go through your queue, so keep a worker running.

## media-library:prune

```bash
php artisan media-library:prune --days=14
```

| Option | Purpose |
|---|---|
| `--days=` | Delete trashed files older than this many days. Defaults to `trash.prune_after_days` (30). |

Permanently deletes trashed files past the age limit, together with their attachments, and removes unfinished upload chunks older than 24 hours. It covers every tenant.

## Scheduling

Schedule `prune` daily. Without it, abandoned chunks and old trash stay on disk.

```php
// routes/console.php
use Illuminate\Support\Facades\Schedule;

Schedule::command('media-library:prune')->daily();
```

Keep `regenerate` out of the schedule. Run it by hand when conversions change.

## Assets and translations

```bash
php artisan filament:assets
php artisan vendor:publish --tag=filament-media-library-translations
```
