'Missing required parameter slug, laravel 8

i have route to get detail data.. but it turns out missing required parameter, i'm using slug as my parameter

Here's my route:

 Route::group([
    'prefix' => '{locale}',
    'where' => ['locale' => '[a-zA-Z]{2}'],
    'middleware' => ['setLocale']
], function () {
    Route::get('/our-work', [App\Http\Controllers\ProjectController::class, 'index'])->name('project.index');
    Route::get('/our-work/{slug}', [App\Http\Controllers\ProjectController::class, 'show'])->name('project.show');

});

My Controller:

public function show($locale, $slug)
    {
        // Get Data Project
        $project = new Client();
        $responseProject = $project->request('GET', env('URL_API') . $locale . '/projects/' . $slug, [
            'headers' => [
                'Authorization' => 'Bearer ' . $token,
                'Accept' => 'application/json',
            ],
        ]);
        $projects = json_decode($responseProject->getBody(), true);
        $dataProjects = (object) $projects;

        return view('pages.detail', [
            'projects' => $dataProjects->data,
        ]);
    }

And here's my href:

<a href="{{ route('project.show',['locale'=>app()->getLocale() ,'slug' => $value['project_slug']]) }}">

Error:

Missing required parameter for [Route: project.show] [URI: {locale}/our-work/{slug}] [Missing parameter: slug]. 

Thankyou



Solution 1:[1]

Problem is from language switcher, need to give params at language

<div class="option">
  <a href="{{ route(\Illuminate\Support\Facades\Route::currentRouteName(), ['en', $params]) }}">
     <div onclick="show1('En')">En</div>
  </a>
  <a href="{{ route(\Illuminate\Support\Facades\Route::currentRouteName(), ['id', $params]) }}">
     <div onclick="show1('Bhs')">Bhs</div>
  </a>
</div>

And set params value on Controller

$params = '';

Solution 2:[2]

<a href="{{ route('project.show',['locale'=>app()->getLocale(), $value['project_slug']]) }}">

This will work.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sutan Firqy
Solution 2 Anuj Kumar