Pharaonic
Loading...

Temporary Signed Route

# Temporary Signed Route

If you would like to generate a temporary signed route URL that expires after a specified amount of time, you may use the temporaryLocalizedSignedRoute method.

1URL::temporaryLocalizedSignedRoute(string $locale, string $name, \DateTimeInterface|\DateInterval|int $expiration, array $parameters = [], bool $absolute = true)

Like if you want to make localized verification you have to follow this steps :
1. New notification extends from the base VerifyEmail.

1namespace App\Notifications;
2 
3use Illuminate\Auth\Notifications\VerifyEmail as BaseVerifyEmail;
4use Illuminate\Notifications\Messages\MailMessage;
5use Illuminate\Support\Carbon;
6use Illuminate\Support\Facades\Config;
7use Illuminate\Support\Facades\Lang;
8use Illuminate\Support\Facades\URL;
9 
10 
11class VerifyEmail extends BaseVerifyEmail
12{
13 /**
14 * Get the verify email notification mail message for the given URL.
15 *
16 * @param string $url
17 * @return \Illuminate\Notifications\Messages\MailMessage
18 */
19 protected function buildMailMessage($url)
20 {
21 return (new MailMessage)
22 ->subject(Lang::get('Verify Email Address'))
23 ->line(Lang::get('Please click the button below to verify your email address.'))
24 ->action(Lang::get('Verify Email Address'), $url)
25 ->line(Lang::get('If you did not create an account, no further action is required.'));
26 }
27 
28 /**
29 * Get the verification URL for the given notifiable.
30 *
31 * @param mixed $notifiable
32 * @return string
33 */
34 protected function verificationUrl($notifiable)
35 {
36 if (static::$createUrlCallback) {
37 return call_user_func(static::$createUrlCallback, $notifiable);
38 }
39 
40 return URL::temporaryLocalizedSignedRoute(
41 locale()->current,
42 'verification.verify',
43 Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)),
44 [
45 'id' => $notifiable->getKey(),
46 'hash' => sha1($notifiable->getEmailForVerification()),
47 ]
48 )
49 }
50}

2. Implement sendEmailVerificationNotification method to use the new VerifyEmail.

1namespace App\Models;
2 
3use App\Notifications\VerifyEmail;
4use Illuminate\Contracts\Auth\MustVerifyEmail;
5use Illuminate\Foundation\Auth\User as Authenticatable;
6use Illuminate\Notifications\Notifiable;
7 
8class User extends Authenticatable implements MustVerifyEmail
9{
10 use Notifiable;
11 
12 protected $fillable = ['name','email','password'];
13 protected $hidden = ['password','remember_token'];
14 protected $casts = ['email_verified_at' => 'datetime'];
15 
16 /**
17 * Send the email verification notification.
18 *
19 * @return void
20 */
21 public function sendEmailVerificationNotification()
22 {
23 $this->notify(new VerifyEmail);
24 }
25}