Home > Blockchain >  Laravel : Missing required parameter for [Route: Region.update]
Laravel : Missing required parameter for [Route: Region.update]

Time:01-10

I encounter a problem on Laravel, I followed the Bootcamp step by step and it was nice, very clear I finished it entirely,

I'm facing trouble when I try to reproduce it on a project of my own, everything goes cool until I try to implement the "edit" part see: https://bootcamp.laravel.com/blade/editing-chirps

I'm getting this error : Missing required parameter for [Route: Region.update]

I've been looking for some times but didn't find anything that worked for me, here is the code :

Controller :

public function edit(Region $region)
    {
        return view('regions.edit', [
            'region' => $region,
        ]);
    }

public function index()
    {
        $regions = Region::all();

        return view('regions.index', [
            'regions' => $regions,
        ]);
    }

public function update(Request $request, Region $region)
    {
        $validated = $request->validate([
            'name' => 'required|string|max:255',
        ]);
 
        $region->update($validated);
 
        return redirect(route('Region.index'));
    }

Index view where I'm passing the data :

<x-dropdown-link :href="route('Region.edit', $region)">
   <img src={{url("build/img/edit.png")}} width="40">
</x-dropdown-link>

Edit view specifically where problems happens.

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

Web route file

Route::resource('Region',RegionController::class)
    ->only(['index', 'create', 'store', 'edit', 'update'])
    ->middleware(['auth', 'verified']);

When I click the link in the index view, I'm redirect on the right link : http://localhost/Region/5/edit ( 5 is an exemple of id ).

But the error from the title appears.

I tried this because I read it here :

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

But it didn't change anything.

Any help would be really appreciate. Thank you for advance

CodePudding user response:

Laravel Resource is case sensitive I think... So, we need to name parameter converter with uppercase like in resource name.

public function edit(Region $Region);

public function update(Request $request, Region $Region);

CodePudding user response:

When using (for your route groups created with resource) Region.update, you must give the id of the model as a parameter to the route:

{{ route('Region.update', $region->id) }}
  • Related