Skip to content

cleaniquecoders/laravel-media-secure

Repository files navigation

Securely display Media

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

You have documents, but want to limit the access to only logged in users, and also have some other sophisticated / complex rules in order to access the documents, then this package is for you.

This package will securely display or download to your media files.

Installation

You can install the package via composer:

composer require cleaniquecoders/laravel-media-secure

Add the following in your route file:

use CleaniqueCoders\LaravelMediaSecure\LaravelMediaSecure;

LaravelMediaSecure::routes();

Then add the following in your app/Providers/AuthServiceProvider.php:

/**
 * Register any authentication / authorization services.
 *
 * @return void
 */
public function boot()
{
    $this->policies[config('laravel-media-secure.model')] = config('laravel-media-secure.policy');
    $this->registerPolicies();
}

You can publish the config file with:

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

By default, all media required logged in user. No guest account.

To add more restriction to all your media, you can update the middleware used:

/**
* Middleware want to apply to the media route.
*/
'middleware' => [
    'auth', 'verified',
],

In case you want more control on who are able to access to the media, you can use the Laravel Policy. You just need to define the policy, then it's done. This package will use the policy to handle more sophisticated and complex rules accessing to your media files.

Usage

Make sure you are using Laravel Medialibrary package.

You upload / add media as documented in Laravel Medialibrary. Then to generate links:

// Get the view URL
// https://your-app.com/media/view/some-random-uuid
$view_url = get_view_media_url($media);

// Get the download URL
// https://your-app.com/media/download/some-random-uuid
$download_url = get_download_media_url($media);

// Get the stream URL
// https://your-app.com/media/stream/some-random-uuid
$stream_url = get_stream_media_url($media);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.