When we build applications in Laravel, sometimes we need to share a file, a route, or even some model data with others in a safe and temporary way. Sending normal links is not always secure, and managing expiry manually can be a headache.
This is where Laravel ShareLink comes in. The Laravel ShareLink package gives us an easy way to create secure, time-limited, and protected links in our Laravel applications.
What is Laravel ShareLink?
Laravel ShareLink is an open-source package that allows developers to generate temporary shareable links for different resources like:
- Files (PDFs, images, documents, etc.)
- Routes (any Laravel route, even with parameters)
- Model previews (like showing a record temporarily)
It is built for modern Laravel package development and works perfectly with Laravel 11 and 12.
Why Use Laravel ShareLink?
Here are some main benefits of using this package:
- Time-Limited Links – You can set expiry in minutes, hours, or days. After expiry, the link will stop working.
- Click Limits – A link can be used only a limited number of times.
- Password Protection – Add an extra layer of security with a password.
- Burn After Reading – Make one-time links that self-destruct after the first click.
- IP Restrictions – Allow or block access for certain IPs.
- Audit Logs – Track who accessed the link, from where, and when.
- Easy Management – Manage links through Artisan commands or code.
With these features, the Laravel ShareLink package makes link sharing safe, flexible, and developer-friendly.
How to Install Laravel ShareLink
Installing this package is simple. Just run the following command:
composer require grazulex/laravel-sharelink
Then publish the migrations and run them:
php artisan vendor:publish --tag="sharelink-migrations"
php artisan migrate
Optionally, publish the config file:
php artisan vendor:publish --tag="sharelink-config"
That’s it. The Laravel ShareLink package is ready to use in your project.
Example Usage of Laravel ShareLink
Here’s a simple example of how to create a secure link:
use Grazulex\ShareLink\Facades\ShareLink;
$link = ShareLink::create('/files/report.pdf')
->expiresIn(60) // expires in 60 minutes
->maxClicks(5) // maximum 5 clicks
->withPassword('secret123') // optional password
->generate();
echo $link->url;
The generated URL will look something like:
https://yourapp.com/share/abc123xyz
Advanced Example
$link = ShareLink::create('/files/secure.pdf')
->burnAfterReading()
->metadata([
'allowed_ips' => ['192.168.1.0/24'],
'denied_ips' => ['192.168.1.100']
])
->generate();
This link will work only once and only for specific IP ranges.
Artisan Commands
The package also comes with handy Artisan commands:
php artisan sharelink:create /files/report.pdf --expires=120 --max-clicks=10
php artisan sharelink:list --active
php artisan sharelink:revoke abc123xyz
php artisan sharelink:prune --days=7
These make it super easy to manage share links from the terminal.
Best Use Cases
The Laravel ShareLink package is very useful in:
- Sharing private reports or invoices with clients
- Giving temporary access to files for vendors or team members
- Creating secure previews for models (like a draft post)
- Sending download links that expire after some time
Basically, anytime you need temporary and secure sharing, Laravel ShareLink is the right choice.
Conclusion
The Laravel ShareLink package is a great example of Laravel package development done right. It is simple, powerful, and covers most real-world sharing needs.
If you want to add secure, time-limited, and flexible sharing in your Laravel application, you should definitely try Laravel ShareLink.
Comments