Home > Back-end >  the put method is not supported
the put method is not supported

Time:06-16

when i try to update my the section name i am having this error: The PUT method is not supported for this route. Supported methods: GET, HEAD. there is the form:

<form action="sections.update" method="POST" autocomplete="off">
                                           @csrf
                                           @method('PUT')
                                           <div >
                                               <input type="hidden" name="id" id="id" value="">
                                               <label for="recipient-name" >section name</label>
                                               <input  name="section_name" id="section_name" type="text">
                                           </div>
                                           <div >
                                               <label for="message-text" >description</label>
                                               <textarea  id="description" name="description"></textarea>
                                           </div>
                                   </div>
                                   <div >
                                       <button type="submit" >confirm</button>
                                       <button type="button"  data-dismiss="modal">close</button>
                                   </div>
                                   </form>

and that is the update controller

public function update(Request $request)
   {
       $id = $request->id;

       $this->validate($request, [

           'section_name' => 'required|max:255|unique:sections,section_name,' . $id,
           'description' => 'required',
       ], [

           'section_name.required' => 'section name is required',
           'section_name.unique' => 'section_name should be unique',
           'description.required' => 'description is required',

       ]);

       $sections = sections::find($id);
       $sections->update([
           'section_name' => $request->section_name,
           'description' => $request->description,
       ]);

       session()->flash('edit', 'the section is edited successfully');
       return redirect('/sections');
   }

CodePudding user response:

you have to pass the id/parameter in your form action when using put method but u re fetching id from form , so you can pass some dummy data on it. Change the form to

<form action="action="{{ route('sections.update', ['section' => '1']) }}" method="POST" autocomplete="off">
  • Related