Catching array from AngularJs using laravel Contoller

Hi I'm new to Laravel and Angularjs. I am trying to send an array from angularjs to a laravel controller. I am not getting any errors, but I have problems finding data in laravel controller and using data Angular code here

 $scope.sendSetField = function (selected_list) {       
        var arr = [];
        angular.forEach(selected_list, function(value, key){
            arr.push(key);
        });
        console.log(arr);
        $http.post("http://localhost/maxo_ats_v1.00/dashboard/jobsDownload", 
         arr).then(function (d̶a̶t̶a̶,̶ ̶s̶t̶a̶t̶u̶s̶,̶ ̶h̶e̶a̶d̶e̶r̶s̶,̶ ̶c̶o̶n̶f̶i̶g̶ response) { 
         alert("success"); 
        },function (d̶a̶t̶a̶,̶ ̶s̶t̶a̶t̶u̶s̶,̶ ̶h̶e̶a̶d̶e̶r̶s̶,̶ ̶c̶o̶n̶f̶i̶g̶ response) { 
            alert("error"); 
        });
   };

      

I can successfully print the data to the console. But can't print data using laravel controller

My controller

 public function downloadJobsList(Request $request)
 {
    $jobs = request('arr');
    dd($jobs);        
 }

      

Route:

Route::post('dashboard/jobsDownload','JobsController@downloadJobsList');

      

+3


source to share


1 answer


The route should look like this:

Route::group(['prefix' => 'maxo_ats_v1.00'], function () {
   Route::post('/dashboard/jobsDownload','JobsController@downloadJobsList');
   //Other Routes
});

      



Also, make sure you have /

before individual routes like /dashboard/jobsDownload

or after route prefix.

+1


source







All Articles