Laravel 9 For Beginners: Your First Project

Route Parameters and Route Model Binding


Route::get('/', function () { return redirect(app()->getLocale()); })->name('main'); Route::prefix('{locale}')->where(['locale' => '[a-zA-Z]{2}'])->middleware('setlocale')->group(function () { Route::middleware(['auth','verified'])->group(function() { Route::resource('users', Admin\UsersController::class ); }); });

This is my routes.But I'm getting "Missing required parameter for route, missing parameter {user}". I didn't get this error before adding multilanguage. How can I fix that error. None of my show functions are working.


What is the URL you're calling? If should be something like /en/users/1 to get a user, because you have the required "locale" now.


I'm calling like this: href="{{ route('', ['user' => $u ]) }}"

  1. First step: Show link in users table: href="{{ route('', ['user' => $u ]) }}"

  2. Routes: Route::get('/', function () { return redirect(app()->getLocale()); })->name('main'); Route::prefix('{locale}')->where(['locale' => '[a-zA-Z]{2}'])->middleware('setlocale')->group(function () { Route::middleware('role:1')->prefix('admin')->name('admin.')->group(function () { Route::resource('users', Admin\UsersController::class ); }); });

  3. My Controller: public function show($locale,User $user) { return view('', compact('user')); }

  4. View file ( Working fine, but If I add it returns error. "Missing required parameter for [Route:] [URI: {locale}/admin/users/{user}] [Missing parameter: user].

I face same problem for every show functions. Can you help to solve this problem?


When I remove this code: x-dropdown-link :href="route(, ['locale' => $locale])" :active="app()->getLocale() == $locale" /x-dropdown-link

It's working fine. In show pages.


Well, you answered your question yourself, the error is in the dropdown link where you put only the locale as a parameter and nothing else. The route is empty as I see, or maybe it was badly formatted, but if you want to redirect to the same route with locale you need to pass user, too.