Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to created a function to edit notes. say for example a user post a note and later wants to edit it. the supposed to click the edit button corresponding to the note and then the modal opens with the note in edit mode

please note i am using the php Laravel framework

What I have tried:

here is my code

My route:

Route::put('save-edits/{note_id}', [NotesController::class, 'saveEdits']) -> name('saveEdits');


My controller: Notescontroller

public function saveEdits(Request $request, $note_id)
{
    $noteContent = $request->input('note_content');

    $note = notes::find($note_id);

    if (!$note) {
        return response()->json(['error' => 'Note not found!'], 404);
    } 
   
    $note->note = $noteContent;
    $note->save();
    

    return view('modal', ['note' => $note]);

}


my html the modal

<div class="modal fade" id="noteModal">
                                      <div class="modal-dialog" role="document">
                                          <div class="modal-content">
                                              <div class="modal-header">
                                                  <h5 class="modal-title">Edit Notes</h5>
                                                  <button type="button" class="close" data-dismiss="modal"><span>×</span>
                                                  </button>
                                              </div>

                                              <div class="modal-body">



                                              <form method="PUT" id="saveEditsForm"  action="{{ route('save-edits', ['note_id' => $note->note_id]) }}" >


                                              @method('PUT')
                                              @csrf

                                     <textarea name="note_content" id="noteContent" cols="30" rows="5" class="form-control bg-transparent" title="Please edit your note" required> </textarea>


                                              <div class="modal-footer">
                                                  <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                                                  <button type="submit" class="btn btn-primary" >Save changes</button>
                                              </div>
                                              </form>


                                          </div>
                                      </div>
                                  </div>

                                  </div>
Posted
Updated 20-May-23 16:09pm
v2
Comments
Andre Oosthuizen 21-May-23 4:18am    
You have more calls to other functions in your 'public function saveEdits' function. Post that code as well as it will help to see how your save function is determined.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900