Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Fifwayte's avatar

Missing required parameter for [Route: types.update]

Hello, I have to use Laravel for a school project and I am having issues with the updating and destroying parts of a controller. Those are my edit, update and destroy functions

public function edit(Types $types)
{
    return view('admin.types.edit', compact('types'));
}

public function update(TypeUpdateRequest $request, Types $type)
{
    $type->name = $request->validated()['name'];
    $type->colour = $request->validated()['colour'];
    if ($request->hasFile('img')) {
        $path = $request->file('img')->store('images/typesImages', 'public');
        $type->image = $path;
    }
    $type->save();

    return redirect()->route('admin.types.index');
}
public function destroy(Types $types)
{
    $types->delete();

    return redirect()->route('admin.types.index');
}

The problem is that, for some reason, the line "<form method="POST" action="{{ route('types.update', $types) }}"" in my edit.blade.php gets me a "Missing required parameter for [Route: types.update] [URI: admin/types/{type}] [Missing parameter: type]." error.

What confuses me is that I have another CRUD controller with the same edit page that I c/p'd from and it's working perfectly on the other one, but this one I can't edit nor delete.

Thank you for taking the time to read my question and sorry if my question is dumb.

0 likes
9 replies
Snapey's avatar

your route requires the id of a type model to edit, but you pass $types which sounds more like a collection

your controller accepts types, but your route says type

public function edit(Types $types)

and

admin/types/{type}

To avoid confusion, and increase consistency, models should be singular, eg Type, single instances of this model should be named singular, eg $type, and collections of that model should be plural, eg $types

2 likes
Fifwayte's avatar

@Snapey Thank you for your answer and the advice, I changed the name of my model.

Unfortunately, the problem persists. I don't really understand because when I try editing a Type of ID one, my URL changes to "/admin/types/1/edit" but I still have the error telling me it is missing a parameter. Shouldn't it not even detect that it's the ID 1 if as the error says, I am not putting a Type in the parameter ?

aleahy's avatar

@Fifwayte The name in the route has to match the name being passed in.

If your route is:

Route::post('admin/types/{type}')->name('types.update');

Then your form should pass in a variable named type because that is what it is expecting:

<form method="POST" action="{{ route('types.update', $type) }}">

Or use an array key to specify the variable name instead:

<form method="POST" action="{{ route('types.update', ['type' => $types]) }}">

But your $types variable should represent a single Type model (or is it a Types model?)

Fifwayte's avatar

@aleahy Hello, thanks for your answer. My route is the following :

		Route::middleware(['auth'])->prefix('admin')->group(function () {
				Route::resource('types', AdminTypesController::class);
				Route::get('/types', [AdminTypesController::class, 'index'])->name('admin.types.index');
        });

(I renamed the model "Type" since it should be named singular apparently)

manar_16667's avatar
Level 1

just change all the $types to $type

1 like
Fifwayte's avatar

Thank you everyone, it's working.

Sorry, I didn't think that a matter of singular/plural would brick it that hard. I can finally sleep.

martinbean's avatar

Thank you everyone, it's working.

@Fifwayte Mark an answer as the best answer so the thread shows as solved in that case.

2 likes

Please or to participate in this conversation.