Pankaj
Pankaj

Reputation: 10095

Route issue in required parameter value - Laravel

Route Code

Route::get(
    '/product-{name}', 
    [
        ProductDetailsController::class, "showProductDetailsMainForm"
    ]
)->name("showProductDetailsMainForm");

Usage

<a href="{!! route('showProductDetailsMainForm', 'name' => 'hello') !!}">

Error Details

Missing required parameters for [Route: showProductDetailsMainForm] [URI: product-{name}]

Am I missing anything?

Upvotes: 0

Views: 108

Answers (3)

STA
STA

Reputation: 34678

For single parameter, you can define like this (without mention the parameter name) :

{{ route('showProductDetailsMainForm', 'hello') }}

Or, with mention the parameter name :

{{ route('showProductDetailsMainForm', ['name' => 'hello']) }}

And change Route::get('/product-{name}',… to Route::get('/product/{name}',…

Upvotes: 1

Donkarnash
Donkarnash

Reputation: 12835

Try

Route::get(
    '/product/{name}', 
    [
        ProductDetailsController::class, "showProductDetailsMainForm"
    ]
)->name("showProductDetailsMainForm");

In view

<a href="{{ route('showProductDetailsMainForm', ['name' => 'hello']) }}">

Upvotes: 1

Vahe Galstyan
Vahe Galstyan

Reputation: 1731

You should use route('showProductDetailsMainForm', ['name' => 'hello']);

Upvotes: 2

Related Questions