NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages

The facade is the recommended default, not the only way in. Three entry points run the same code: the MediaLibrary facade (shortest), the manager RoundlyConsulting\MediaLibrary\MediaLibraryManager — the facade's root, a container singleton also aliased media — injected through the constructor (same API, explicit dependency, no static calls), and actions (single-purpose classes with execute(), for composing into your own actions, jobs and commands).

Inject the manager

use RoundlyConsulting\MediaLibrary\MediaLibraryManager;

final class AvatarController
{
    public function __construct(private MediaLibraryManager $media) {}

    public function store(Request $request): Media
    {
        return $this->media->for($request->user())->addFromRequest('avatar')->toBucket('avatar');
    }
}

Call an action

use RoundlyConsulting\MediaLibrary\Actions\MoveMediaAction;
use RoundlyConsulting\MediaLibrary\Actions\RegenerateVariantsAction;

app(MoveMediaAction::class)->execute($media, $otherUser, 'gallery', 'cold');
app(RegenerateVariantsAction::class)->execute($media, only: ['thumb'], force: true);

Facade method → action

Facade methodAction
add*() / draft() → toBucket()AddMediaAction
attach()AttachMediaAction
bindDraft()BindDraftMediaAction
move() / moveToDisk()MoveMediaAction
moveVariantsToDisk()MoveMediaVariantsAction
copy()CopyMediaAction
replace()ReplaceMediaAction
delete() / clear() / clearBucket()DeleteMediaAction
regenerate() / variants()->regenerate()RegenerateVariantsAction
pruneDrafts()PruneDraftsAction
  • Every mutation — from the facade, a for() handle, the trait or a Media model method — funnels through one manager verb that resolves one action from the container, so a container override of an action applies everywhere.
  • MediaLibrary::fake() swaps the manager in the container too, so injected managers are faked as well. Calling an action directly bypasses the fake.
  • GenerateVariantsAction is an internal building block (it renders exactly the definitions it is handed) — regenerate through RegenerateVariantsAction or MediaLibrary::regenerate().

Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

More ways to support, including crypto

By donating, you agree to our donation terms.

Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.