-
Notifications
You must be signed in to change notification settings - Fork 11k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[8.x] Added ability to define temporary URL macro for storage #40100
[8.x] Added ability to define temporary URL macro for storage #40100
Conversation
How does this work across multiple drivers? What I'm using |
Ahh good point, I hadn't considered that. If you defined the macro, it would have overridden the I've just pushed up a new change that I think should handle this though. I've added a method called For example, you could now use it like this: // Define the logic using:
Storage::disk('local')->buildTemporaryUrlUsing(function ($path, $expiration, $options) {
return 'using local';
});
// Not that you'd want to do this, but just as an example...
Storage::disk('s3')->buildTemporaryUrlUsing(function ($path, $expiration, $options) {
return 'using s3';
});
// Call the logic using:
$url = Storage::temporaryUrl('file.jpg', now()->addMinutes(5)); // $url is: 'using local';
$url = Storage::disk('s3')->temporaryUrl('file.jpg', now()->addMinutes(5)); // $url is: 'using s3'; Do you think this would be a suitable approach? |
I don't think you need macros at all. |
Yeah, good shout to be fair! I've made some changes now so that it doesn't use macros and holds the closures in a I also split the else-if out because I thought it was looking a bit bloated with the changes I'd just made, but I'm happy to switch that back if you'd prefer :) |
Here is the correct syntax This should go in AppServiceProvider, boot method. <?php
use Illuminate\Support\Facades\Storage;
Storage::disk('local')->buildTemporaryUrlsUsing(function ($path, $expiration, $options) {
return $path.'?expires='.$expiration;
}); |
Hi! This PR adds the ability for you to add your own
getTemporaryUrl()
logic for theStorage
facade.At the moment, you can define a
getTemporaryUrl()
method on a file system adapter and it'll get called. So, this addition mirrors that same approach so that you can add the functionality via a macro.I think this would be really handy for if you don't have direct access to make changes to the adapter itself. For example, you could use the macro so that you can use temporary URLs when using the
local
storage disk. Of course, you'd still need to make sure you create a controller to handle the actual request, but I think it could tidy up the code a bit.As a really basic example, you could have something like this:
So, you can call the method in a much more Laravel-y way:
If this is something you might want to pull in, please let me know if there are any changes I need to make 😄