shahadh/laravel-temporary-links
最新稳定版本:v1.0.0
Composer 安装命令:
composer require shahadh/laravel-temporary-links
包简介
Generate temporary, expiring access links for Laravel applications
README 文档
README
A Laravel package for generating temporary, expiring access links for users to view/download content securely.
Features
- ✅ Time-Limited Links – Links expire after a set time (e.g., 24 hours)
- ✅ One-Time Use Links – Restrict access to a single open/download
- ✅ IP & Device Restrictions – Limit access to specific IPs or devices
- ✅ Webhook Integration – Get notified when a link is accessed
Installation
You can install the package via composer:
composer require shahadh/laravel-temporary-links
Publish the migrations and config:
php artisan vendor:publish --tag="temporary-links-migrations" php artisan vendor:publish --tag="temporary-links-config"
Run the migrations:
php artisan migrate
Usage
Basic Usage
// Add the trait to your model use Shahadh\TemporaryLinks\Traits\HasTemporaryLinks; class Document extends Model { use HasTemporaryLinks; } // Create a temporary link $document = Document::find(1); $link = $document->createTemporaryLink(); // Get the URL $url = $link->getUrl();
Link Options
// Create a link that expires in 1 hour $link = $document->createExpiringTemporaryLink(60); // Create a single-use link $link = $document->createSingleUseTemporaryLink(); // Create a link with IP restriction $link = $document->createTemporaryLink([ 'restrict_ip' => $request->ip() ]); // Create a link with device restriction $link = $document->createTemporaryLink([ 'restrict_device' => true ]); // Create a link with custom path $link = $document->createTemporaryLinkForPath('/downloads/secret-file.pdf');
Handling Access
By default, accessing a link will redirect to the model or path. You can customize this behavior by adding a handleTemporaryAccess method to your model:
public function handleTemporaryAccess($link, $request) { // Custom access logic here return Storage::download($this->file_path); }
Webhook Integration
Configure webhooks in the config file to receive notifications when links are accessed or expire.
Configuration
See the config/temporary-links.php file for all configuration options.
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-09