Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

187
Vistas
I can't pass the request value to controller laravel

Hi I'm new to Laravel and I'm having problem in passing the request properly in my controller which is a resource for update function I'm using Laravel 8. there is no error with the syntax it just return the request is empty. I paste my code for references.

my AJAX Request

    let url = '/companystructure/1';
$.ajaxSetup({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        }
                    });
        $.ajax({
                            url: url,
                            type: "PATCH",
                            data: {
                                'fullname' : 'albert'
                            },
                            processData: false,
                            contentType: false,
                            success: function(response) {
                                console.log(response);
                                
                                //alert(response);
                                //location.reload();
                            },
                            error: function (xhr, ajaxOptions, thrownError) {
                                var error = $.parseJSON(xhr.responseText) || thrownError;
                                var errorMsg = error['message'] || thrownError;
                                var errorObj = error.errors || [];
                                if (errorObj) {
                                    Object.keys(errorObj).forEach(function (key){
                                        if (errorObj[key][0].length <= 1 ) {
                                        errorMsg = errorMsg + '<br/>' + errorObj[key];
                                        } else {
                                        errorMsg = errorMsg + '<br/>' + errorObj[key][0];
                                        }
                                    });
                                }
                                md.showNotification(errorMsg, 'danger');
                            }
                        });

and here is controller

public function update(Request $request, $id)
{
    return response()->json($request);
}

and here is my Route

Route::resource('companystructure', CompanyStructureController::class);

this is the return I receive from my controller

enter image description here

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

type: 'PATCH' does not exists on HTTP methods thus will not be recognized by Laravel. Try this:

      let url = '/companystructure/1';
$.ajaxSetup({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        }
                    });
        $.ajax({
                            url: url,
                            type: "POST", /// UPDATE
                            data: {
                                'fullname' : 'albert',
                                '_method': 'PATCH',   /// UPDATE
                            },
                            processData: false,
                            contentType: false,
                            success: function(response) {
                                console.log(response);
                                
                                //alert(response);
                                //location.reload();
                            },
                            error: function (xhr, ajaxOptions, thrownError) {
                                var error = $.parseJSON(xhr.responseText) || thrownError;
                                var errorMsg = error['message'] || thrownError;
                                var errorObj = error.errors || [];
                                if (errorObj) {
                                    Object.keys(errorObj).forEach(function (key){
                                        if (errorObj[key][0].length <= 1 ) {
                                        errorMsg = errorMsg + '<br/>' + errorObj[key];
                                        } else {
                                        errorMsg = errorMsg + '<br/>' + errorObj[key][0];
                                        }
                                    });
                                }
                                md.showNotification(errorMsg, 'danger');
                            }
                        });
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda