Missing required parameter for [Route: login] [URI: {locale}/login]

Subsequently, “Missing required parameter for [Route: login] [URI: {locale}/login]” appears with Route::has(‘login’) in blade. In fact, I faced this error after using Laravel 9 Localization in my Laravel app.

Missing required parameter for [Route: login] [URI: {locale}/login].

Before, moving forward, please check another Laravel tutorial below to confirm that your Laravel 9 localization works fine.

Missing required parameter for [Route: login] [URI: {locale}/login]

First of all, “Missing required parameter for [Route: login] [URI: {locale}/login]” also has a similar error as below.

  1. Missing required parameters for [Route: login] [URI: login]
Missing required parameter for [Route: login] [URI: {locale}/login]

Further, the error mentioned in number later is related to the missing required parameter while our subjected error is related to the localization and blade.

Assumption – Your login route expects a ‘locale‘ parameter but when you visit a page that requires authentication as a guest, the Authenticate Middleware is called.

General Discussion

In fact, you may notice that your Laravel app works fine when I logged in but the error comes when you are not logged int. Further, you can resolve this error by doing with two approaches.

  1. Firstly, add the current locale using {{ route(‘login’, app()->getLocale()) }}.
  2. Secondly, add @guest to trigger Laravel @guest authentication feature.

Solution: Laravel Locale in Blade File

Indeed, you need to add the current locale using {{ route(‘login’, app()->getLocale()) }} in the blade.php file.

@if (Route::has('login'))
   <div class="hidden fixed top-0 right-0 px-6 py-4 sm:block">
	@auth
	    <a href="{{ url('/home') }}" class="text-sm text-gray-700 dark:text-gray-500 underline">Home</a>
	    @else
		<a href="{{ route('login') }}" class="text-sm text-gray-700 dark:text-gray-500 underline">Log in</a>
   		   @if (Route::has('register'))
			<a href="{{ route('register') }}" class="ml-4 text-sm text-gray-700 dark:text-gray-500 underline">Register</a>
		   @endif
	@endauth
   </div>
@endif

In fact, using the {{ route(‘login’, app()->getLocale()) }} will remove missing required parameter for [Route: login] [URI: {locale}/login] error in Laravel app.

route::has(‘login’) route::has(‘login) and similarly route(‘login’) only works with named routes.

Laravel Always Default Locale

Additionally, you may know that app()->getLocale() is always Laravel default locale but not the current Laravel locale. It is better to set the locale in session and then call it, above example is for explanation only.

App\Http\Middleware\Authenticate Solution ?

Meanwhile, During the internet search, similar to me, you may read that App\Http\Middleware\Authenticate need to be updated with similar code example. Of course, I tried all these before writing this tutorial for you. Now, you may ask that why I put this in the end? In fact, I wrote these lines for reader’s education not the solution.

# App\Http\Middleware\Authenticate
if (! $request->expectsJson()) {
    return route('login');
    //return route('/login');
    //return route('login', ['locale' => app()->getLocale()]);
    //return route('login', ['locale' => 'en']);
}

Reference Documents

Share

You may also like...