Working with private files in Laravel usually means involving third-party services like S3 or DigitalOcean. But what if you’re in a local development environment or have a lightweight project? You might not want to depend on third-party cloud services.
Luckily, Laravel makes it easy to serve temporary URLs for files stored locally. This approach can speed up development and simplify file sharing.
You just need to change the FILESYSTEM_DISK
to local from your .env
file.
FILESYSTEM_DISK=local
Next, check your config/filesystems.php
file. Under the 'local' disk configuration, set 'serve' => true
, if it's not there you can add it.
Once your configuration is set, you can use Laravel's Storage::temporaryUrl()
to create URLs that expire after a defined time, keeping your files secure.
Here's a more detailed version of this article to help you understand better if you could catch on: https://laraveleco.com/laravel-how-to-create-temporary-url-for-files-in-local-disk/
If you liked this article and want to support, you can do so by buying me a coffee.
Top comments (0)