Home > Enterprise >  Laravel 9 - Missing required parameter for [Route: trial.show] [URI: evaluation/{evaluation}/trial/{
Laravel 9 - Missing required parameter for [Route: trial.show] [URI: evaluation/{evaluation}/trial/{

Time:03-30

I have an evaluation model that has many trials. I can create a trial and query through my trials and output them to my evaluation.show view. My problem is when I want to create a link to my trial.edit or trial.show routes, I keep getting error Missing required parameter for [Route: trial.show] [URI: evaluation/{evaluation}/trial/{trial}] [Missing parameter: trial]. I know I am missing something obvious, but I've exhausted my brain output.

web.php

...
Route::get('/evaluation/{evaluation}/trial/create', App\Http\Livewire\Trial\Create::class)->name('trial.create');
Route::get('/evaluation/{evaluation}/trial/{trial}/edit', App\Http\Livewire\Trial\Edit::class)->name('trial.edit');
Route::get('/evaluation/{evaluation}/trial/{trial}', App\Http\Livewire\Trial\Show::class)->name('trial.show');
...

livewire/evaluation/show.blade.php

    ...
@foreach($trials as $trial)
    <a href="{{route('trial.show', $trial->id)}}" >
@endforeach
    ...

Livewire/Evaluation/Show.php

...
public function mount(Evaluation $evaluation, Trial $trial) {
    $this->evaluation = $evaluation;
    $this->trial = $trial;
}

public function render()
{
    $trials = Trial::where('evaluation_id', $this->evaluation->id)->get();

    return view('livewire.evaluation.show', compact('trials'));
}

CodePudding user response:

Your route(s) take two parameters ({evaluation} and {trial}), you only pass one in {{route('trial.show', $trial->id)}}.

Add the evaluation id (assuming $evaluation->id holds that id):

<a href="{{route('trial.show', [$evaluation->id, $trial->id])}}" >
  • Related