rossnp's avatar
Level 11

Laravel Signed URL's with Subdomain

Hi,

I'm generating a signed URL that is emailed to customers using the code below. The code is being generated in the mailer:

Url::temporarySignedRoute('viewProof', now()->addWeek(), ['proof' => $proof->id]);

This works correctly, however because the URL is being generated from a subdomain in Laravel, which is being used as a staff administration area, the signed URL is being prefixed with the subdomain, e.g. https://admin.domain.com/signature...

It should be https://domain.com/signature...

I've taken a look at the documentation and spent quite some time on Google to see if you can pass a URL to the method, but this seems to have been overlooked. Is there a way to change the URL? as I'm assuming this is quite a common scenario.

Thanks, Ross

0 likes
5 replies
bobbybouwmann's avatar
Level 88

You can pass in a 4th parameter to get the absolute or relative url. By default this parameter is set to true. If you set it to false it will only return the url without the domain. You can then prefix it with the url yourself. You can for example get this value from the APP_URL or from some other config you're using ;)

$url = Url::temporarySignedRoute('viewProof', now()->addWeek(), ['proof' => $proof->id], false);
3 likes
yvomenezes's avatar

Thanks for your answer ! It was exactly what I was looking for.

sharvadze's avatar

Hey Bobby, you comment was very helpful, thanks for that. I have a problem with the URL when using api middleware - it include the "api" itself. This is what I get: http://localhost:3000/api/register?email...

Any thoughts how I can possibly get rid of it? Thanks!

Please or to participate in this conversation.