Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel URL facade temporarySignedRoute to external url

Tags:

php

laravel

I'm using Laravel 8 to generate a temporary signed route and pass some params, but I'd like my URL to take me to some URL of my choosing rather than a page in my project.

For context, my Laravel 8 project is an API, so there are no views, my API is then consumed by a front-end project written in Nuxt.

I've tried adding my URL to the first arg of temporarySignedRoute but it says that my route isn't found.

$verifyURL = URL::temporarySignedRoute(
  'https://example.com/account/verify', Carbon::now()->addHours(24), ['contact' => 5, 'team' => 'john']
);

What am I missing or what workaround is there here?

UPDATE

So it turns out that I don't need to take the user to an external URL, but it seems that the wrong URL is being generated by URL::temporarySignedRoute.

The start of my generated URL is (for example) https://example.com/api/contact/verify and I need the URL to be https://api.example.com/api/contact/verify

So the same domain, except a sub-domain.

It looks like the APP_URL isn't being read because I changed it and it has no impact, and besides, this is used elsewhere, so I tried updating the URL with:

$verifyURL = URL::temporarySignedRoute(
  'contact.verify', Carbon::now()->addHours(24), ['contact' => 5, 'team' => 'john]
);

// fix for wrong URL
$verifyURL = str_replace('example.com', 'api.example.com', $verifyURL);

However, this appears to have an invalid signature when the link provided by $verifyURL is clicked? How can I get the api part at the beginning?

like image 242
Ryan H Avatar asked Oct 18 '25 10:10

Ryan H


1 Answers

URL::temporarySignedRoute() has a fourth parameter called $absolute which is a boolean. So if you want to prepend a custom url rather than the default url used by Laravel, this is the variable to change.

The default value for $absolute is true. Therefore in order to prepend your own custom url, be sure to change it to false first as below:

$verifyURL = URL::temporarySignedRoute(
  'contact.verify', Carbon::now()->addHours(24), ['contact' => 5, 'team' => 'john], false // The $absolute value
);

Then concatenate your custom url:

$your_custom_url . $verifyURL;
like image 118
Phil Avatar answered Oct 20 '25 23:10

Phil