raza9355
1 month ago

store multiple data in multiple column on post laravel

Posted 1 month ago by raza9355

this is my controller what i have tried

 public function getTranslation(Request $request){

    
    $dataa = new trans();
    $lang = new language();
    $data = $request->all();
    
    foreach ($request->get('translation')  as $key=>$translation):
      
        $detail = $dataa;
        $detail['translation.'.$key];
        $detail->translation = $translation;
        dd($detail);
    endforeach;
}

this is ajax

jQuery(document).ready(function () {
                  $('#saveBtn').on('click', function (e) {
                    var access = [];
          $('input[name^="translation"]').each(function() {
              access.push(this.value);
          });
                      var value = $("#ajax-crud-modal").find('input[name="post_id"]').val();
                      console.log(value);
                      e.preventDefault();
                      $.ajaxSetup({
                          headers: {
                              'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                          }
                      });
                      $.ajax({
                          url: '{{ url("/surname/translation") }}',
                          type: 'POST',
                          data: {
                            ethnicity: $('[name=ethnicity]').val(),
                            translation: access,
                          
                          },
                          
                          success: function (result, exception) {
                            $('#ajax-crud-modal').modal('hide');
                          

                          },
                          error: function (jqXHR, exception) {
                              alert(jqXHR.status + ' - ' + exception);
                          }
                      });
                  });
              });

this is the ajax i am sending to the controller from translation i am getting array i want to add that store data of array on new column like when i post data all fields value will save in new column in db i dont know how to achieve that from controller i am new to laravel help will be appreciated

Please sign in or create an account to participate in this conversation.