PHPackages                             bekwoh/laravel-media-secure - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. bekwoh/laravel-media-secure

Abandoned → [https://github.com/cleaniquecoders/laravel-media-secure](/?search=https%3A%2F%2Fgithub.com%2Fcleaniquecoders%2Flaravel-media-secure)Library[Image &amp; Media](/categories/media)

bekwoh/laravel-media-secure
===========================

Securely display Media

3.3.0(1mo ago)7660MITPHPPHP ^8.2 | ^8.3 | ^8.4CI passing

Since Oct 15Pushed 1mo agoCompare

[ Source](https://github.com/cleaniquecoders/laravel-media-secure)[ Packagist](https://packagist.org/packages/bekwoh/laravel-media-secure)[ Docs](https://github.com/cleaniquecoders/laravel-media-secure)[ RSS](/packages/bekwoh-laravel-media-secure/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (30)Versions (20)Used By (0)

Laravel Media Secure
====================

[](#laravel-media-secure)

[![Latest Version on Packagist](https://camo.githubusercontent.com/959952ee1f8a8a127cdf4b624dbcf93f37ebc6f1654e89f0e8f835fa7c472645/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636c65616e69717565636f646572732f6c61726176656c2d6d656469612d7365637572652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cleaniquecoders/laravel-media-secure)[![PHPStan](https://github.com/cleaniquecoders/laravel-media-secure/actions/workflows/phpstan.yml/badge.svg)](https://github.com/cleaniquecoders/laravel-media-secure/actions/workflows/phpstan.yml)[![run-tests](https://github.com/cleaniquecoders/laravel-media-secure/actions/workflows/run-tests.yml/badge.svg)](https://github.com/cleaniquecoders/laravel-media-secure/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/cc2cc731b571167fb80507f000653e9e7f8251e4ce4e712935f8d10dee69e9f7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636c65616e69717565636f646572732f6c61726176656c2d6d656469612d7365637572652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cleaniquecoders/laravel-media-secure)

Secure your media file access with authentication and policy-based authorization. Built on top of [Spatie Laravel MediaLibrary](https://spatie.be/docs/laravel-medialibrary/v11/introduction), this package provides secure view, download, and stream endpoints with fine-grained access control.

Features
--------

[](#features)

- Secure media URLs with UUID-based routing
- Three access types: **view**, **download**, and **stream**
- **Signed URLs** for time-limited access without authentication
- Authentication requirement (configurable)
- Policy-based authorization with parent model delegation
- Customizable middleware stack
- ETag/Last-Modified caching headers for performance
- Memory-efficient file streaming for large files
- Helper functions for URL generation

Installation
------------

[](#installation)

```
composer require cleaniquecoders/laravel-media-secure
```

Publish the config file:

```
php artisan vendor:publish --tag="media-secure-config"
```

Quick Start
-----------

[](#quick-start)

### 1. Generate Secure URLs (Authenticated)

[](#1-generate-secure-urls-authenticated)

```
use Spatie\MediaLibrary\MediaCollections\Models\Media;

// Get view URL: /media/view/{uuid}
$viewUrl = get_view_media_url($media);

// Get download URL: /media/download/{uuid}
$downloadUrl = get_download_media_url($media);

// Get stream URL: /media/stream/{uuid}
$streamUrl = get_stream_media_url($media);
```

### 2. Generate Signed URLs (Shareable)

[](#2-generate-signed-urls-shareable)

Signed URLs allow sharing media with external users without requiring authentication. URLs are cryptographically signed and expire after a configurable time.

```
// Generate signed URL (default expiration from config)
$signedUrl = get_signed_view_url($media);

// Generate signed URL with custom expiration (in minutes)
$signedUrl = get_signed_download_url($media, 30); // Expires in 30 minutes

// Generate signed URL with DateTime expiration
$signedUrl = get_signed_stream_url($media, now()->addHours(24));

// Using the Facade
use CleaniqueCoders\LaravelMediaSecure\Facades\LaravelMediaSecure;

$url = LaravelMediaSecure::signedViewUrl($media);
$url = LaravelMediaSecure::signedDownloadUrl($media, 60);
```

### 3. Create a Policy for Your Model (Required when `strict = true`)

[](#3-create-a-policy-for-your-model-required-when-strict--true)

```
namespace App\Policies;

use App\Models\Document;
use App\Models\User;

class DocumentPolicy
{
    public function view(User $user, Document $document): bool
    {
        return $user->id === $document->user_id;
    }

    public function stream(User $user, Document $document): bool
    {
        return $user->id === $document->user_id;
    }

    public function download(User $user, Document $document): bool
    {
        return $user->id === $document->user_id;
    }
}
```

### 4. Register the Policy

[](#4-register-the-policy)

```
// In AuthServiceProvider
protected $policies = [
    \App\Models\Document::class => \App\Policies\DocumentPolicy::class,
];
```

Signed URLs
-----------

[](#signed-urls)

Signed URLs are perfect for:

- Sharing files via email or messaging
- Embedding media in external applications
- Providing temporary access to clients
- API integrations where authentication is impractical

### Configuration

[](#configuration)

```
// config/laravel-media-secure.php

'signed' => [
    'enabled' => env('LARAVEL_MEDIA_SECURE_SIGNED_ENABLED', true),
    'prefix' => 'media-signed',
    'route_name' => 'media.signed',
    'expiration' => env('LARAVEL_MEDIA_SECURE_SIGNED_EXPIRATION', 60), // minutes
],
```

### Environment Variables

[](#environment-variables)

```
LARAVEL_MEDIA_SECURE_SIGNED_ENABLED=true
LARAVEL_MEDIA_SECURE_SIGNED_EXPIRATION=60
```

Documentation
-------------

[](#documentation)

For detailed documentation, see [docs/README.md](docs/README.md).

- [Getting Started](docs/01-getting-started/README.md)
- [Configuration](docs/02-configuration/README.md)
- [Authorization](docs/03-authorization/README.md)
- [Signed URLs](docs/04-signed-urls/README.md)

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Nasrul Hazim Bin Mohamad](https://github.com/nasrulhazim)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance90

Actively maintained with recent releases

Popularity19

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity73

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~74 days

Recently: every ~62 days

Total

18

Last Release

49d ago

Major Versions

1.2.0 → 2.0.02024-03-21

2.2.1 → 3.0.02025-07-24

PHP version history (4 changes)1.0.0PHP ^8.1

2.0.0PHP ^8.1 | ^8.2 | ^8.3

2.2.0PHP ^8.1 | ^8.2 | ^8.3 | ^8.4

3.0.0PHP ^8.2 | ^8.3 | ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/b57069d0f4b634f65eccc6e5d5848990e25968d45ec2cf46d626c6a4658f944b?d=identicon)[nasrulhazim.m](/maintainers/nasrulhazim.m)

---

Top Contributors

[![nasrulhazim](https://avatars.githubusercontent.com/u/10341422?v=4)](https://github.com/nasrulhazim "nasrulhazim (103 commits)")

---

Tags

laravelmediamedialibraryphpspatie-laravel-medialibrarylaravelcleaniquecoderslaravel-media-secure

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/bekwoh-laravel-media-secure/health.svg)

```
[![Health](https://phpackages.com/badges/bekwoh-laravel-media-secure/health.svg)](https://phpackages.com/packages/bekwoh-laravel-media-secure)
```

###  Alternatives

[saasykit/laravel-open-graphy

An awesome open graph image (social cards) generator package for Laravel.

13057.0k](/packages/saasykit-laravel-open-graphy)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[ace-of-aces/laravel-image-transform-url

Easy, URL-based image transformations inspired by Cloudflare Images.

1756.4k](/packages/ace-of-aces-laravel-image-transform-url)[johncarter/filament-focal-point-picker

An image focal point picker for Filament Admin.

4326.5k1](/packages/johncarter-filament-focal-point-picker)[ralphjsmit/laravel-glide

Auto-magically generate responsive images from static image files.

4719.6k5](/packages/ralphjsmit-laravel-glide)[spatie/laravel-og-image

Generate OG images for your Laravel app

305.2k](/packages/spatie-laravel-og-image)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
