shahadh/laravel-temporary-links

Generate temporary, expiring access links for Laravel applications

Installs: 4

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/shahadh/laravel-temporary-links

v1.0.0 2025-03-09 19:11 UTC

This package is auto-updated.

Last update: 2026-01-09 20:59:09 UTC


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.