Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

184
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda