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

Top comments (0)