Skip to content

MediaFlow Facade ​

MediaFlow\Laravel\Facades\MediaFlow gives you the same operations as the UI, for controllers, queued jobs and console commands. The facade alias MediaFlow is registered automatically.

php
use MediaFlow\Laravel\Facades\MediaFlow;

Methods ​

MethodReturnsDescription
upload(UploadedFile $file, array $options = [])MediaValidate, process and store a file.
delete(Media|int $media, bool $purgeStorage = true)boolSoft-delete the record and, by default, remove the original and variant files. Fires MediaDeleted.
move(Media|int $media, ?int $targetFolderId)MediaMove to a folder, or to the root with null.
rename(Media|int $media, string $newDisplayName)MediaChange the display name. The stored file is not renamed.
optimize(Media|int $media, array $options = [])arrayRe-encode or resize a stored image. See Image Optimization.
createFolder(string $name, ?int $parentId = null, ?string $ownerId = null, ?string $tenantId = null)MediaFolderCreate a folder.
testStorageConnection(?string $disk = null)arrayWrite, read and delete a probe file on a disk and report whether it worked.
disk(?string $disk = null)StorageAdapterThe storage adapter for a disk.
delivery()DeliveryAdapterThe URL resolver.
authorize(Closure $callback)voidRegister an extra access check. See Access Control.

Uploading ​

php
$media = MediaFlow::upload($request->file('photo'), [
    'folder' => 'avatars',        // folder ID, name or path; missing folders are created
    'collection' => 'profiles',
    'visibility' => 'public',     // or 'private'
    'thumbnails' => true,
]);

All upload options:

OptionDefaultDescription
diskdefault_disk, or private_disk for private filesTarget disk.
folder / folder_idrootFolder ID, name or path such as blog/covers.
collectiondefaultCollection name.
visibilitypublicpublic or private.
thumbnailsimages.generate_thumbnailsGenerate preset variants.
owner_idcurrent user IDOwner, used by per-user scoping.
tenant_idnullStored with the record; not enforced yet.
optimizeimages.auto_optimizeConvert and downscale on upload.
format, quality, max_width, max_heightimage settingsPer-upload image settings.
max_kb, allowed_mimesconfigStricter upload rules for this call.

Validation failures throw MediaFlow\Laravel\Exceptions\MediaUploadException with a readable message.

php
use MediaFlow\Laravel\Exceptions\MediaUploadException;

try {
    $media = MediaFlow::upload($file, ['folder' => 'invoices', 'visibility' => 'private']);
} catch (MediaUploadException $e) {
    return back()->withErrors(['file' => $e->getMessage()]);
}

Folders, moving and renaming ​

php
$folder = MediaFlow::createFolder('2026 Campaigns');
$child  = MediaFlow::createFolder('Spring', $folder->id);

MediaFlow::move($media, $child->id);
MediaFlow::rename($media, 'hero-banner.webp');

Deleting ​

php
MediaFlow::delete($media);          // record and files
MediaFlow::delete($media, false);   // record only, keep files in storage

Storage checks from code ​

php
$result = MediaFlow::testStorageConnection('s3');
// ['success' => true, 'message' => '...', 'details' => ['disk' => 's3', ...]]

Released under the MIT License.