Hook: media.uploaded
Last updated on May 17, 2026 20:13
Overview
Type: Action
Location: app/Services/MediaService.php, MediaController.php
Fired after a file is uploaded and saved to database. Use this for post-processing tasks like image optimization, thumbnail generation, or syncing to external storage.
Parameters
| Param | Type | Description |
|---|---|---|
$media |
Media | Newly created media record |
$file |
UploadedFile | Original uploaded file |
$data |
array | Validated upload metadata |
Usage Example
Hook::addAction('media.uploaded', function ($media, $file) {
if (str_starts_with($media->mime_type, 'image/')) {
dispatch(new GenerateWebpVariant($media));
}
});
Related Hooks
- media.url - Rewrite media URLs
- media.delete.should - Prevent deletion