The Laravel ShareLink package helps you create, manage, and secure temporary share links for files, routes, and models. This package enables simple sharing with custom expiration and maximum clicks, and provides an API for managing shares, such as extending the time for an existing share. Here's a basic example from the package's documentation:
use Grazulex\ShareLink\Facades\ShareLink; // Share a file with expiration$link = ShareLink::create('/path/to/document.pdf') ->expiresIn(60) // 60 minutes ->maxClicks(5) ->withPassword('secret123') ->generate(); echo $link->url; // https://yourapp.com/share/abc123xyz
This package has a lot of advanced features, such as sharing a route, an Eloquent model, or even specifying IP restrictions for share links:
$link = ShareLink::create('/secure/document.pdf') ->expiresIn(60) ->burnAfterReading() // Self-destructs after first access ->metadata([ 'allowed_ips' => ['192.168.1.0/24', '10.0.0.1'], 'denied_ips' => ['192.168.1.100'] ]) ->generate();
This package also provides a CLI to generate share links if you want to create them from the command line instead of via your code:
$ php artisan sharelink:list --active$ php artisan sharelink:create /reports/quarterly.pdf \ --expires=72 \ --max-clicks=10 \ --password=Q4Report2024
Main Features
- Multiple Resource Types - Share files, routes, and model previews seamlessly
- Time-Limited Access - Set expiration dates and usage limits
- Password Protection - Optional password gates for enhanced security
- Rate Limiting - Per-token rate limiting to prevent abuse
- IP Filtering - Allow/deny specific IP addresses or CIDR ranges
- Signed URLs - Optional Laravel signed route integration
- Burn After Reading - One-time access links that self-destruct
- Comprehensive Auditing - Track access patterns, IPs, and timestamps
- Advanced Security - Password throttling, brute force protection
- Flexible Delivery - Support for X-Sendfile, X-Accel-Redirect, and streaming
- Management API - Revoke and extend links programmatically
- CLI Commands - Full Artisan command support
- Observability - Built-in logging and metrics integration
- Test-Friendly - Comprehensive test coverage with easy mocking
💻 Check it out on GitHub: Grazulex/laravel-sharelink