Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel 9 – Missing required parameter for [Route: trial.show] [URI: evaluation/{evaluation}/trial/{trial}] [Missing parameter: trial]

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    ...
@foreach($trials as $trial)
    <a href="{{route('trial.show', $trial->id)}}" class="block hover:bg-gray-50">
@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'));
}

>Solution :

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])}}" class="block hover:bg-gray-50">
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading