title: Laravel DataTable custom search
body: <p>I have a DataTable on my website that uses server side processing which works as intended. However, I am adding additional search fields that draw from the DataTable and refine the search results for players. So for example, which hand they shoot with, their position, name, etc.</p>
  
  <p>The filter search boxes work just fine for data that I did not alter via the columns settings. In this case, the player name was altered to create an anchor tag using both the first and last name. When I search that table column, the DataTable outputs the following error:</p>
  
  <p><strong>Error</strong></p>
  
  <pre><code>datatables warning: table id=DataTables_Table_0 - exception message mb_strtolower() expects parameter 1 to be string, array given
  </code></pre>
  
  <p>I've researched the problem but there doesn't seem to be too much documentation on the error. If anyone has any suggestions on how to solve this, it would be greatly appreciated!</p>
  
  <p><strong>Search Box</strong></p>
  
  <pre><code>&lt;div class="form-group row"&gt;
      &lt;label for="name" class="col-sm-2 col-form-label"&gt;Player&lt;/label&gt;
      &lt;div class="col-sm-10"&gt;
          {{ Form::text('name', null, array('id' =&gt; 'name', 'class' =&gt; 'form-control form-control-alternative', 'id' =&gt; 'name')) }}
       &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p><strong>DataTable Controller</strong></p>
  
  <pre><code>  public function playersFilter()
    {
      $cards = DB::table('cards')-&gt;leftJoin('players', 'cards.player_id', '=', 'players.id')-&gt;leftJoin('teams', 'cards.team_id', '=', 'teams.id')-&gt;select('cards.*', 'teams.league', 'teams.abbrv', 'players.first', 'players.last', 'players.handness', 'players.nationality')-&gt;where('cards.position', '!=', 'G')-&gt;orderBy('cards.overall', 'desc')-&gt;get();
  
      return Datatables::of($cards)-&gt;make(true);
    }
  </code></pre>
  
  <p><strong>JQuery</strong></p>
  
  <pre class="lang-js prettyprint-override"><code>  &lt;script type="text/javascript"&gt;
      $(document).ready(function(){
        var table = $('.players-adv-search').DataTable({
          'processing'  : true,
          'language'    : {
            'loadingRecords': '&amp;nbsp;',
            'processing': '&lt;i class="fa fa-spinner fa-medium fa-fw"&gt;&lt;/i&gt;&lt;span class="loading-text"&gt;Loading...&lt;/span&gt;'
          },
          'serverSide'  : true,
          'info'        : false,
          'ajax'        : "{{ route('players.filter') }}",
          'columns'     : [
              { "data": null, render: function ( data, type, row ) {
                  var type = data.card_type;
                  var type_final = type.replace('-', ' ').replace('-', ' ').toLowerCase();
  
                  return type_final.replace(/(^([a-zA-Z\p{M}]))|([ -][a-zA-Z\p{M}])/g,
                  function($1){
                      return $1.toUpperCase();
                  });
              }},
              { "data": "league", className: 'text-center' },
              { "data": "abbrv", className: 'text-center' },
              { "data": null, render: function ( data, type, row ) {
                  // This is the column that corresponds with the search box
                  if (type === 'display') {
                    data = '&lt;a href="card/' + data.id + '" target="_blank"&gt;' + data.first + ' ' + data.last + '&lt;/a&gt;';
                  }
                  return data;
              }},
              { "data": "position", className: 'text-center' },
              { "data": "player_type", className: 'text-center' },
              { "data": "handness", className: 'text-center' },
              { "data": null, className: 'search-syn text-center', render: function ( data, type, row ) {
                    var synergies = ['NP', 'BL', 'X', 'BM', 'TN', 'DK', 'AD', 'WK', 'WM', 'RS', 'M', '1T', 'TK', 'WC', 'SP', 'FB', '', 'HH'];
                    var syn_ids = data.synergy_ids.split(',');
                    var syn_pts = data.synergy_pts.split(',');
                    var data = '';
  
                    $.each(syn_ids,function(i){
                      data += synergies[syn_ids[i]-1] + '&lt;span class="search-syn-pts"&gt; [' + syn_pts[i] + ']&lt;/span&gt; ';
                    });
  
                  return data;
              }},
              { "data": "overall", className: 'text-center' },
              { "data": "deking", className: 'text-center' },
              { "data": "handeye", className: 'text-center' },
              // .. Additional statistics
          ],
          'lengthChange': false,
          'paging'      : true,
          'pageLength'  : 50,
          'ordering'    : false,
        });
  
        // Name Search
        // Giving an error
        $('#name').change(function() {
          table.columns(0).search(this.value).draw();
        });
  
        // League Search
        $('#league').change(function() {
          table.columns(1).search(this.value).draw();
        });
  
        // Handness Search
        $('#handness').change(function() {
          table.columns(6).search(this.value).draw();
        });
  </code></pre>