Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!