John Davidson

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

0 comments
Message:


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)}}" 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'));
}


My Answer:
> In your `web.php` file, you need to define the route for `trial.show` and `trial.edit` routes with the required parameters.

Here is an example of how you can define these routes:

php
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');


Make sure to replace `App\Http\Livewire\Trial\Edit::class` and `App\Http\Livewire\Trial\Show::class` with the actual classes that handle the editing and showing of trials.

Once you have defined these routes, you can use the `route()` helper function in your views to generate the correct URLs for these routes. For example:

php
Edit Trial


This will generate a URL like `/evaluation/1/trial/2/edit` where `1` is the evaluation ID and `2` is the trial ID.

Make sure that you are passing the correct evaluation and trial IDs when generating the URLs for these routes.

Rate this post

4 of 5 based on 5871 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us