cleaniquecoders / laravel-media-secure
Securely display Media
Installs: 1 592
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 0
Forks: 0
Open Issues: 0
Requires
- php: ^8.1 | ^8.2 | ^8.3
- illuminate/contracts: ^9.0 | ^10.0 | ^11.0
- spatie/enum: ^3.13
- spatie/laravel-enum: ^3.0
- spatie/laravel-medialibrary: ^10.5 | ^11.5
- spatie/laravel-package-tools: ^1.14.0
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.0
- orchestra/testbench: ^8.0 | ^9.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5 | ^10.0
README
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.