0
votes

I tried to create a new route with a controller that uses an id parameter, and a link to this. The error is when I try to create a link to a controller. The error that I got is:

"Missing required parameters for [Route: notas.detalle] [URI: detalle/{id}]. (View: /var/www/html/laravel/blog/resources/views/producto.blade.php)"

The route:

Route::get('detalle/{id}', 'productoController@detalle')>name('notas.detalle');

The blade template:

@foreach($notas as $nota)
    <a href="{{ route('notas.detalle'), $nota }}">{{$nota->id}}</a>
    {{$nota->created_at}}
    {{$nota->updated_at}}
@endforeach

What can be the problem?

2
You have a typo - the $nota variable is outside the function parenthesis. route('notas.detalle'), $nota should be route('notas.detalle', $nota) - Qirel
Voting to close as off-topic due to the issue being a typo. - Qirel
@Qirel thnaks! that was the error. - jdoe1980

2 Answers

1
votes

Laravel route helpers can take as a second parameter, an associative array with all the keys (require parameter) and it values.

so is your case it would be something like this

route('notas.detalle', ['id' => 1])

but it could be multiple parameter so is your route had something like 'notas/{id}/student/{student}

then you could do the following.

route('notas.detalle', ['id' => 1, student => 129483])

here is a link to the docs where you can see this in more details. https://laravel.com/docs/5.8/routing#named-routes

0
votes

The problem is that the variable must be after comma. I think this will work:

<a href="{{ route('notas.detalle', $nota->id) }}">{{$nota->id}}</a>