Where to add parameter to Route: verification.notice {language}/email/verify
Asked Answered
I

3

8

Missing required parameters for [Route: verification.notice] [URI: {language}/email/verify]

I added the laravel email verification to my project, after using localization. But now I have the problem that the Route: verification.notice is missing a parameter. I know that I need to add/pass the app()->getLocale() parameter to the route but can't find where

I tried searching all the routes and the URLs in the project and also checked the VerificationController.php and the verify.blade.php. But I didn't find the route with the missing parameter. Also, I couldn't find someone else online with the same problem.

web.php

Route::group([
    'prefix' => '{language}',
    'where' => ['{language}' => '[a-Za-Z]{2}'],
    'middleware' => 'SetLanguage',
],
    function () {

        Route::get('/', function () {
            return view('welcome');
        })->name('Welcome');

        Auth::routes(['verify' => true]);

        Route::get('/home', 'HomeController@index')->name('home');

        Route::namespace('User')->group(function () {
            Route::get('/profile', 'UserController@editProfile')->name('profile');
            Route::put('profile', 'UserController@updateProfile');
        });

        Route::namespace('Admin')->group(function () {
            Route::get('/dashboard', 'AdminController@index')->name('dashboard');
        });
    });

UserController

class UserController extends Controller
{
    public function __construct()
    {
        $this->middleware('verified');
    }

    public function editProfile()
    {
        $user = User::where('id', Auth()->user()->id)->first();

        return view('user.profile', compact('user'));
    }
}

----edit----

SetLanguage.php

namespace App\Http\Middleware;

use App;
use Closure;

class SetLanguage
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        App::setLocale($request->language);

        return $next($request);
    }
}
Indulgence answered 16/12, 2019 at 10:36 Comment(3)
Show your SetLanguage middleware code.Hardset
@DilipHirapara I added my SetLanguage.php fileIndulgence
@Indulgence How did you solve the problem?Masefield
R
4

Simply : override the middleware: EnsureEmailIsVerified

  1. Create a new middleware with same name and insert : app()->getLocale();
public function handle($request, Closure $next, $redirectToRoute = null)
{
  if (! $request->user() ||
     ($request->user() instanceof MustVerifyEmail &&
       ! $request->user()->hasVerifiedEmail())) {
      return $request->expectsJson()
          ? abort(403, 'Your email address is not verified.')
          : Redirect::route($redirectToRoute ?: 'verification.notice', app()->getLocale());
  }
  
  return $next($request);
}
  1. Modify App\Http\Kernel.php and replace :
\Illuminate\Auth\Middleware\EnsureEmailIsVerified

by

\App\Http\Middleware\EnsureEmailIsVerified::class

Finally, you can have also a problem with the verification.verify route

Override this route with a new notification class like this : Note : URL::temporarySignedRoute can pass parameters like language

<?php

namespace App\Notifications;

use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\Config;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage;

class VerifyEmail extends Notification
{
    /**
     * The callback that should be used to build the mail message.
     *
     * @var \Closure|null
     */
    public static $toMailCallback;

    /**
     * Get the notification's channels.
     *
     * @param  mixed  $notifiable
     * @return array|string
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    /**
     * Build the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        $verificationUrl = $this->verificationUrl($notifiable);

        if (static::$toMailCallback) {
            return call_user_func(static::$toMailCallback, $notifiable, $verificationUrl);
        }

        return (new MailMessage)
            ->subject(Lang::get('Activer mon compte client'))
            ->line(Lang::get('Veuillez cliquer sur le bouton ci-dessous pour activer votre compte client.'))
            ->action(Lang::get('Activer mon compte client'), $verificationUrl)
            ->line(Lang::get('Si vous n\'avez pas demandé la création d\'un compte client '.config('app.name').', ignorez simplement cet e-mail.'));
    }

    /**
     * Get the verification URL for the given notifiable.
     *
     * @param  mixed  $notifiable
     * @return string
     */
    protected function verificationUrl($notifiable)
    {
        return URL::temporarySignedRoute(
            'verification.verify',
            Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)),
            [
                'language' => app()->getLocale(),
                'id' => $notifiable->getKey(),
                'hash' => sha1($notifiable->getEmailForVerification()),
            ]
        );
    }

    /**
     * Set a callback that should be used when building the notification mail message.
     *
     * @param  \Closure  $callback
     * @return void
     */
    public static function toMailUsing($callback)
    {
        static::$toMailCallback = $callback;
    }
}

And add the declaration into user model :

// OVERRIDE
    /**
     * Send email verification.
     * @call function
     */
    public function sendEmailVerificationNotification() {
        $this->notify(new VerifyEmail);
    }
Repossess answered 6/7, 2021 at 11:7 Comment(0)
R
0

I faced the same problem before like yours.

As you said you didn't add {language}/ before the some path in your views check your path in all view and alter it to be like this:

href="{{ route('somePath', app()->getLocale() ) }}"

make sure to alter all the pages to contain the correct path with language prefix in your views.

Reliant answered 16/12, 2019 at 11:3 Comment(1)
As I said i checkt all the views for the path but can't find itIndulgence
F
0

The workaround is to leave it as it is, but change only url to "after verification" page. You can do it by storing user's locale while creating new user and then in VerificationController in verify method you do sth like:

$this->redirectTo = ($user->locale == 'pl') ? 'https://example.net/pl/dziekujemy' : 'https://example.net/en/thank-you';
Freemon answered 16/4, 2020 at 9:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.