DEV Community

Abrar Ahmad
Abrar Ahmad

Posted on

Laravel Package for Generating Local Disk Temporary URL

A while ago I wrote an article on how you can generate the temporary URL for a local disk like we do for S3. You can read the full article here https://dev.to/abrardev99/laravel-temporary-url-for-local-storage-driver-50of.

I needed the same functionality in multiple projects so I ended up adding the same code again and again. So I created a package to achieve temporary URL generation 😍.

First Release

Packages come with some nice configurations.

This is the contents of the published config file:

return [
    'disk' => ['local'],

    'middleware' => ['web', 'signed']
];
Enter fullscreen mode Exit fullscreen mode

Usage

Configuration

This package needs zero configuration, just install and it's good to go. However, if your local disk is different or you want to add another disk, you can configure it. You can add multiple local disks in the config using the disk key.

The package applies web and signed middleware on routes by default, however, you can configure middleware(s) using the middleware key.

Generate Temporary URL

You can use the same syntax used for S3 disk.

Storage::disk('local')->temporaryUrl('file.txt', now()->addMinutes(5));
Enter fullscreen mode Exit fullscreen mode

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay