3

Hi I am new to Laravel and Angularjs I am trying to send an array from angularjs to laravel controller i am not getting any errors but I have problem catching data in laravel controller and using the data Here the Angular code

 $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 able to print the data in console successfully.But failing to print data using laravel controller

My controller

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

Route:

Route::post('dashboard/jobsDownload','JobsController@downloadJobsList');
5
  • Use a var_dump("Start") at the start of method to check if its reaching the controller. Commented Jul 13, 2017 at 5:57
  • nothing happening Commented Jul 13, 2017 at 6:02
  • There could me multiple issues here, could be CORS or something in the middleware. Are angularjs and laravel on the same domain? Commented Jul 13, 2017 at 6:05
  • yes i same domain Commented Jul 13, 2017 at 6:06
  • $jobs = Input::all(); solved my issue and @Sajal suggestions too thanks Commented Jul 13, 2017 at 8:32

1 Answer 1

1

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 a / either in front of individual routes such as /dashboard/jobsDownload or after the route prefix.

Sign up to request clarification or add additional context in comments.

10 Comments

My bad, missed a ] after the prefix. See the updated answer.
i added $jobs = Input::all(); and it worked and your routes too thanks.
Hi Sajal i got another issue can u help
Sure, what is the problem?
public function downloadJobsList(Request $request) { // $jobs = CnfFormField::select('id', 'name', 'email', 'created_at')->get(); $jobs = Input::all(); // return view('jobs.columnSelect',compact['data']); $data = Jobs::select($jobs)->get(); Excel::create('Job', function($excel) use ($data) { $excel->sheet('mySheet', function($sheet) use ($data) { $sheet->fromArray($data); }); })->download('xlsx'); }
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.