Hook: media.url
Last updated on May 21, 2026 05:09
Overview
Type: Filter
Location: app/Services/MediaService.php
Rewrites media file URLs. Commonly used to route media through a CDN or apply image transformation services like Cloudflare Images or Imgix.
Parameters
| Param | Type | Description |
|---|---|---|
$url |
string | Original storage URL |
$media |
Media | Media model instance |
Return
Must return string - final public URL.
Usage Example
Hook::addFilter('media.url', function (string $url, $media) {
return str_replace('/storage/', 'https://cdn.example.com/', $url);
});
Related Hooks
- media.uploaded - Action fired after upload
- media.delete.should - Gate to prevent deletion