cleaniquecoders / laravel-media-secure
安全显示媒体
2.1.0
2024-05-26 08:00 UTC
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
您有文档,但只想限制登录用户访问,并且还需要一些其他复杂规则来访问文档,那么这个包就是为您准备的。
此包将安全地显示或下载您的媒体文件。
安装
您可以通过 composer 安装此包
composer require cleaniquecoders/laravel-media-secure
在您的路由文件中添加以下内容
use CleaniqueCoders\LaravelMediaSecure\LaravelMediaSecure; LaravelMediaSecure::routes();
然后在您的 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(); }
您可以使用以下命令发布配置文件
php artisan vendor:publish --tag="laravel-media-secure-config"
默认情况下,所有媒体都需要登录用户。没有访客账户。
要为所有媒体添加更多限制,您可以更新使用的中间件
/** * Middleware want to apply to the media route. */ 'middleware' => [ 'auth', 'verified', ],
如果您想对谁可以访问媒体有更多控制,您可以使用 Laravel Policy。您只需定义策略即可。此包将使用策略来处理更复杂和复杂的媒体文件访问规则。
用法
请确保您正在使用 Laravel Medialibrary 包。
您可以将媒体上传/添加,如 Laravel Medialibrary 中的文档所述。然后生成链接
// 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);
测试
composer test
更新日志
有关最近更改的更多信息,请参阅 更新日志
贡献
有关详细信息,请参阅 贡献指南
安全漏洞
请查看我们如何报告安全漏洞的 安全策略
鸣谢
许可
MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件