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

pdlbibek's avatar

Creating an edit user form

I was trying to update a user, so added the edit method (to redirect to the edit form page) and update method (to update the data from the form) in my controller.

Here is the edit button: <a href="{{ route('admin.edit', $user->id) }}"</a>

But I am getting this error when clicking the edit button: The GET method is not supported for this route. Supported methods: POST, DELETE. Am I doing anything wrong here?

My Routes:

Route::get('users', 'UserlistController@display')->name('admin.userlist');
    Route::post('users', 'UserlistController@store')->name('admin.create');
    Route::post('users/edit', 'UserlistController@edit')->name('admin.edit');
    Route::post('users/edit?{id}', 'UserlistController@update')->name('admin.update');
    Route::delete('users/{id}', 'UserlistController@destroy')->name('admin.deleteuser');

My Methods in the controller:

 public function edit($id)
    {
        $title = 'Update User';
        $user = User::findOrFail($id);
        return view('dashboard.edit', compact('title'))->withUser($user);

    }

    public function update($id, Request $request)
    {
        $updateuser = User::findOrFail($id);
        $this->validate($request, [
            'name' => 'required',
            'useravatar' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
        ]);

        $imageName = time().'.'.$request->useravatar->extension();  
        $request->useravatar->move(public_path('img'), $imageName);
        $input = $request->all();
        $input['useravatar'] = $imageName;

        $updateuser->fill($input)->save();
        Session::flash('success', 'Successfully updated!');
    }
0 likes
2 replies
tisuchi's avatar
tisuchi
Best Answer
Level 70

@pdlbibek

It's because you defined route('admin.edit') as a POST and you are trying to access this route by using GET.

So, change

Route::post('users/edit', 'UserlistController@edit')->name('admin.edit');

to

Route::get('users/edit', 'UserlistController@edit')->name('admin.edit');
1 like
pdlbibek's avatar

If I change post to get, the $id is not passed in the edit() method.

Oh wait! I changed it to get('users/edit/{id}' ... Now it is working good.

Thanks man!

Please or to participate in this conversation.