I'm trying to generate URLs signed in Laravel 8 so that the application's clients can cancel the event without needing access. I'm using multi-tenant with two subdomains foo.domain.com and bar.domain.com. However, Laravel generates signed URLs only for the main domain. Is there any way to change Laravel's behavior to understand and generate a signed URL for the subdomains?
public function generateLink($id, $username, $whatsapp)
{
return Url::temporarySignedRoute('confirmpage', now()->addMinutes(20), [
'id' => $id,
'user' => $username,
'whatsapp' => $whatsapp
]);
}
My Answer:
To generate signed URLs for subdomains in Laravel 8, you can modify the `config/session.php` file to include the subdomain in the `domain` configuration.
Here's how you can do it:
1. Open the `config/session.php` file in your Laravel project.
2. Find the `domain` key in the `config/session.php` file and update it to include the subdomain. For example, you can set it to `.domain.com` to include all subdomains under `domain.com`.
php
'domain' => env('SESSION_DOMAIN', '.domain.com'),
3. Save the changes to the `config/session.php` file.
4. Now, when you generate a signed URL using the `Url::temporarySignedRoute` method, Laravel will generate a signed URL that includes the subdomain.
php
public function generateLink($id, $username, $whatsapp)
{
return Url::temporarySignedRoute('confirmpage', now()->addMinutes(20), [
'id' => $id,
'user' => $username,
'whatsapp' => $whatsapp
]);
}
With this configuration, Laravel will generate signed URLs that work for subdomains as well.
Rate this post
3 of 5 based on 4998 votesComments