Search code examples
phplaravellaravel-5laravel-5.7laravel-route

Is there a solution for Missing required parameters for [Route:....?


Could someone please help me with this error? I have been struggling for days now. enter image description here

Missing required parameters for [Route: helper.update] [URI: helper/{id}]. (View: D:\Training\LaravelProjects\helps\resources\views\helper\edit.blade.php)

I have followed the documentation and still i can't figure out what is wrong. This is my code.

Web.php

Route::group(['prefix' => 'helper'], function (){
 Route::get('/create', [
    'uses' => 'HelperController@create',
    'as' => 'helper.create'
 ]);

 Route::get('/{id}/edit', [
    'uses' => 'HelperController@edit',
    'as' => 'helper.edit'
 ]);

 Route::get('/{id}', [
    'uses' => 'HelperController@show',
    'as' => 'helper.show'
 ]);

 Route::post('/', [
    'uses' => 'HelperController@store',
    'as' => 'helper.store'
 ]);

 Route::put('/{id}', [
    'uses' => 'HelperController@update',
    'as' => 'helper.update'
 ]);

 Route::delete('/{id}', [
    'uses' => 'HelperController@destroy',
    'as' => 'helper.destroy'
 ]);
});

HelperController.php

public function edit($id)
{
    $helper = Helper::find($id);
    return view('helper.edit', compact('helper'));
}

index.blade.php

<tbody>
                @foreach($helpers as $helper)
                <tr>
                    <td>{{ $helper->name }}</td>
                    <td>{{ $helper->email }}</td>
                    <td>{{ $helper->telephone }}</td>
                    <td>{{ $helper->city }}</td>
                    <td>{{ $helper->district }}</td>
                    <td>{{ $helper->province }}</td>
                    <td>{{ $helper->category }}</td>
                    <td>
                        <a href="{{ route('helper.edit', $helper->id) }}" class="edit">
                            <i class="fas fa-pencil-alt" title="Edit" style="font-size: 16px"></i>
                        </a>
                        <a href="#deleteEmployeeModal" class="delete" data-toggle="modal" data-widget="">
                            <i class="fas fa-trash" title="Delete" style="font-size: 16px"></i>
                        </a>
                    </td>
                </tr>
                @endforeach

All I want is to open the edit.blade.php file once I click edit link. The delete part is incomplete and please ignore that. Also, the id is being passed as a parameter but stil says it's missing. enter image description here


Solution

  • In resources\views\helper\edit.blade.php make sure to pass the helper id to the update post/put html form

    {{ route('helper.update', $helper->id) }}
    

    Hope this helps