0

i would like to passing data from my javascript function and send it into controller this is my code

ajax.js

let dataNewMemoData = JSON.stringify(createnewMemoData);

$.ajax({
    url: '/crew_memo/submitdata',
    method: 'POST',
    contentType: 'json',
    data: {data: dataNewMemoData},
    headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
    success : function(data){
       console.log(data) 
    },
    error : function(jqXHR,textStatus,thrownError){
     console.log(jqXHR)
    }
})

this is my route from web

web.php

Route::post('/crew_memo/submitdata', 'CrewProgramController@saveData');

controller.php

public function saveData(Request $request){
    $getData = $request->tableplacement->employeNik;
    return dd($getData);
}

i want to access this value, so basically i want to access value inside array on array

enter image description here

i want to access emplyeNik or any other value inside that array how can i do that

5
  • i would like to access it in laravel controller Commented Apr 9, 2020 at 4:02
  • i got an error Trying to get property 'tableplacement' of non-object Commented Apr 9, 2020 at 4:06
  • this is an image error imgur.com/A6ZvWau Commented Apr 9, 2020 at 4:07
  • @AndySong this is the image imgur.com/tlfoizw, i got Call to a member function all() on null Commented Apr 9, 2020 at 4:18
  • yeah i already import this Request use Illuminate\Http\Request; Commented Apr 9, 2020 at 4:22

1 Answer 1

1

I believe this will do.

foreach (request()->input('tableplacement') as $value) {
   //$value is each item in the array.

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

1 Comment

i got this imgur.com/oSFkyEv, invalid argument supplied for foreach

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.