'Internal Serber Error 500 when trying to update data using AJAX and Laravel-8

I'm trying to update data by opening a modal(bootstrap 3.3.6) where the new value can be inserted and then sent with Ajax to a Laravel-8 controller. I keep getting a "Failed to load resource: the server responded with a status of 500 (Internal Server Error)" and I can't figure out if my mistake is on the Ajax side or in the controller. Any help would be appreciated.

homepage.blade.php

 <!-- Modal update -->
            <div class="modal" id="updateModal" tabindex="-1" role="dialog" aria-labelledby="updateModalLabel">
                <div class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header bg-success">
                            <h5 class="modal-title text-white" id="updateModalLabel">Prénom & nom modifiés</h5>
                        </div>
                        <div class="modal-body">
                            <input type="text" class="form-control" id="newGest" name="newGest" placeholder="John Doe">
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default" data-dismiss="modal">Fermer</button>
                            <button type="button" id="updateGest" class="btn btn-primary">Modifier</button>
                        </div>
                    </div>
                </div>
            </div>

            <!--Ajax---->
            <script>
                $('#updateGest').on('click', function() {
                    let gestionnaire_id = $('#nom_gestionnaire').val();
                    let nom_gestionnaire = $('#newGest').val();
                    let updateData = {
                        'gestionnaire_id': gestionnaire_id,
                        'nom_gestionnaire': nom_gestionnaire
                    }
                    //alert(JSON.stringify(updateData));
                    $.ajax({
                        type: 'POST',
                        url: "{{ route('gestionnaire.update') }}",
                        data: updateData,
                        success: function(data) {
                            $('#updateModal').modal('hide');
                            getGestionnaires();
                        },
                        error: function(err) {
                            console.log('error');
                        }
                    });
                });
            </script>

CrudController.php with update function

public function updateGestionnaire(Request $request)
    {
        $data = ['nom_gestionnaire' => $request->nom_gestionnaire];
        $gest = Gestionnaire::find($request->gestionnaire_id);
        $gest->update($data);

        return redirect()->route('homepage'); 
    } 

web.php

Route::post('gestionnaire/update',[CrudController::class,'updateGestionnaire'])->name('gestionnaire.update');


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source