title: Laravel 5 AJAX Sort Order data (jQuery Sortable) with no HTML form
body: <p>I'm to trying to store a sort order to each article within a help centre for my new site using Laravel 5 and having a bit of trouble getting it to work. I'm using jQuery UI's <code>.sortable</code> for arranging the elements on the page, and since there are going to be multiple sections throughout the site where areas are sortable, my jQuery script is built in a way for a 'one script for all' purposes. Hence the use of <code>data-*</code> attributes and route name references.</p>
  
  <p>Here is the code I've got so far:</p>
  
  <p><strong>routes.php</strong></p>
  
  <pre><code>Route::post('admin/help-centre/category/{category_id}/section/{section_id}/article/sort-order', 'AdminHelpCentreArticleController@sortOrder');
  </code></pre>
  
  <p><strong>AdminHelpCentreArticleController.php</strong></p>
  
  <pre><code>public function sortOrder($category_id, $section_id)
  {
      /* Return ------------------------------------- */
          return [
              'category_id' =&gt; $category_id,
              'section_id' =&gt; $section_id
          ];
  }
  </code></pre>
  
  <p><strong>show.blade.php (Admin Article Listing)</strong></p>
  
  <pre><code>&lt;ul id="help-center-articles-sort" class="sortable"&gt;
      @foreach ($helpCentreArticles as $helpCentreArticle)
          &lt;li class="sortable-element" data-sortable-element-id="{{ $helpCentreArticle-&gt;id }}"&gt;
              &lt;a href="{{ action('AdminHelpCentreArticleController@show', array($helpCentreCategory-&gt;id, $helpCentreSection-&gt;id, $helpCentreArticle-&gt;id)) }}" target="_self"&gt;{{ $helpCentreArticle-&gt;title }}&lt;/a&gt;
          &lt;/li&gt;
      @endforeach
  &lt;/ul&gt;
  
  &lt;a href="{{ $helpCentreSection-&gt;id }}/article/sort-order" target="_self" class="button bm-remove w-full sortable-save" data-sortable-id="help-center-articles-sort"&gt;Save Order&lt;/a&gt;
  </code></pre>
  
  <p><strong>scripts.js (includes CSRF Token <code>_token</code>)</strong></p>
  
  <pre><code>var csrfToken = $('meta[name="csrf-token"]').attr('content');
  
  $.ajaxPrefilter(function(options, originalOptions, jqXHR) {
      if (options.type.toLowerCase() === 'post')
      {
          options.data += options.data?'&amp;':''; // add leading ampersand if `data` is non-empty
          options.data += '_token=' + csrfToken; // add _token entry
      }
  });
  
  $(document).ready(function() {
      $('.sortable').sortable();
  
      $('.sortable-save').on('click', function(e) {
          e.preventDefault();
  
          var route = $(this).attr('href'),
              sortableID = $(this).attr('data-sortable-id');
  
          var data = $('#' + sortableID + ' .sortable-element').map(function() { 
              return $(this).attr('data-sortable-element-id');
          }).get();
  
          $.ajax({
              type: 'POST',
              url: route,
              dataType: 'json',
              data: { id_array: data },
              success: function(data) {
                  console.log(data);
              }, error: function(data) {
                  console.log(data);
              },
          });
      });
  });
  </code></pre>
  
  <p>Everything so far is working in terms of the return response in the console, which is <code>Object {category_id: "1", section_id: "1"}</code>. But no matter what I try, I cannot seem to pass through the <code>data</code> map to the controller to use it.</p>
  
  <p>I've tried a bunch of guesswork since I cannot find a single decent tutorial on AJAX in Laravel 5 anywhere, and I've tried things such as adding a <code>$data</code> parameter to the <code>sortOrder()</code> method, I've tried <code>Input::all()</code> and <code>Request::all</code> but it all returns errors (I'm guessing cause it's not an actual form?).</p>
  
  <p>Once I've got the data to be passed through to the controller I'll be able to save the sort order to the database easily enough. But I can't quite get to that stage, any ideas?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I should probably note that I do have a <code>HelpCentreArticle</code> model and a <code>HelpCentreArticleRequest</code> request too, here's some of the code from each file in case they are also needed:</p>
  
  <p><strong>HelpCentreArticle.php</strong></p>
  
  <pre><code>class HelpCentreArticle extends Model {
      protected $fillable = [
          'category_id',
          'section_id',
          'title',
          'content',
          'excerpt',
          'is_visible',
          'sort_order',
          'created_by',
          'updated_by',
      ];
  }
  </code></pre>
  
  <p><strong>HelpCentreArticleRequest.php</strong></p>
  
  <pre><code>class HelpCentreArticleRequest extends Request {        
  
      /* Authorization ------------------------------ */
          public function authorize()
          {
              return true;
          }
  
  
      /* Validation rules --------------------------- */
          public function rules()
          {
              $rules = [
                  'title' =&gt; 'required|min:3',
                  'content' =&gt; 'required|min:10',
              ];
  
              return $rules;
          }
  
  }
  </code></pre>
  
  <p>I wasn't sure if I needed to add <code>HelpCentreSectionRequest $request</code> as the last parameter of the <code>sortOrder()</code> method, so I could use <code>$request-&gt;all()</code> but it just returns a <code>422 (Unprocessable Entity)</code> in the console log.</p>