skip to Main Content

When I am clicking on the edit button I am getting this error.

Missing required parameter for [Route: admin.clues.update][URI: admin/clues/{game}/{id}] [Missing parameter: id] here is the edit button

 <button class="btn btn_action actionButton" style="background-color: #66a4e4;">
 <a href="{{ route('admin.clues.edit', ['game' => $game->slug, 'id' => $clue->id]) }}">
 <i class="fa fa-pencil icon_span" aria-hidden="true"></i></a>
 </button>

Web route:

Route::get('/{id}/edit', [ClueController::class, 'edit'])->name('admin.clues.edit');
Route::patch('/{id}', [ClueController::class, 'update'])->name('admin.clues.update');

Form action of edit page:

<form action="{{ route('admin.clues.update', ['game' => $game, 'id' => $clue->id]) }}"
    id="clue-edit-form"
    method="post"
    enctype="multipart/form-data"
>

Controller:

public function edit($game, Clue $clue)
{
    $game = Game::where('slug', $game)->first();
    return view('admin.clues.edit', ['game' => $game, 'clue' => $clue]);
}

/**
 * Update clue
 */
public function update(Request $request )
{
    return redirect()->route('admin.clues');
}

2

Answers


  1. Assuming you are not doing any bindings in the RouteServiceProvider, you may need to change the signature of the edit function as implicit binding of the resource Clue would not be effective.

    public function edit($game, $id)
    {
        $game = Game::where('slug', $game)->first();
    
        $clue = Clue::find($id);
    
        return view('admin.clues.edit', ['game' => $game, 'clue' => $clue]);
    }
    
    Login or Signup to reply.
  2. The error you’re encountering is due to a missing parameter in the route for the "edit" button. In your route definition, you have specified the {id} parameter, but in your button link, you are passing the id parameter. The names need to match for Laravel to resolve the correct route.

    your code should look something like this :

    <button class="btn btn_action actionButton" style="background-color: #66a4e4;">
        <a href="{{ route('admin.clues.edit', ['id' => $clue->id]) }}">
            <i class="fa fa-pencil icon_span" aria-hidden="true"></i>
        </a>
    </button>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search