title: draggable rows using ajax in laravel
body: <p>i'm here trying to make a draggable rows for table and update the change in the database, so i follow on tutorial the drag and drop works fine but the changes not save in the database. 
  this is the tutorial i'm follow
  <a href="https://shareurcodes.com/blog/create-drag-and-droppable-datatables-using-jquery-ui-sortable-in-laravel" rel="nofollow noreferrer">https://shareurcodes.com/blog/create-drag-and-droppable-datatables-using-jquery-ui-sortable-in-laravel</a></p>
  
  <p>and here my codes</p>
  
  <p>searchController</p>
  
  <pre><code>class SearchController extends Controller {
      public function index() {
          // $customers = Customer::all();
          $customers = Customer::orderBy('order', 'ASC') - &gt; select('id', 'first_name', 'last_name', 'email', 'phone') - &gt; get();
          return view('search.search', compact('customers'));
      }
  
      public function updateOrder(Request $request) {
          $customers = Customer::all();
          //$customer = Customer::findOrFail($id);
  
          foreach($customers as $customer) {
              $customer - &gt; timestamps = false;
              $id = $customer - &gt; id;
              foreach($request - &gt; order as $order) {
                  if ($order['id'] == $id) {
                      $customer - &gt; update(['order' =&gt; $order['id']]);
                  }
                  //if($order['id'] = $id){
                  //                    $customer-&gt;update($request-&gt;all());
                  //                }
              }
          }
          return response('Update Successfully', 200);
      }
  }
  </code></pre>
  
  <p>search.blade.php</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(function() {
          $("#table").DataTable();
          $("#tablecontents").sortable({
              items: "tr",
              //   cursor: 'move',
              opacity: 0.6,
              update: function() {
                  sendOrderToServer();
              }
          });
  
          function sendOrderToServer() {
              let order = [];
              $('tr.row1').each(function(index) {
                  order.push({
                      id: $(this).attr('data-id'),
                      position: index + 1
                  });
  
              });
              $.ajax({
                  type: "POST",
                  dataType: "json",
                  url: "{{ url('search.search') }}",
                  data: {
                      order: order,
                      _token: '{{csrf_token()}}'
                  },
                  success: function(response) {
                      if (response.status == "success") {
                          console.log(response);
                      } else {
                          console.log(response);
                      }
                  }
              });
          }
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>route</p>
  
  <pre><code>Route::post('search/search','searchController@updateOrder');
  </code></pre>
  
  <p>this is the table</p>
  
  <pre><code>Schema::create('customers', function (Blueprint $table) {
          $table-&gt;increments('id');
          $table-&gt;string('first_name');
          $table-&gt;string('last_name');
          $table-&gt;string('email')-&gt;unique();
          $table-&gt;string('phone');
          $table-&gt;integer('order');
          $table-&gt;timestamps();
  </code></pre>
  
  <p>when i drag and drop this error in the console</p>
  
  <p>jquery.min.js:4 POST <a href="http://adminproject.test/search.search" rel="nofollow noreferrer">http://adminproject.test/search.search</a> 404 (Not Found)</p>