title: Laravel : Data-table search option not working using relationship table field
body: <p>I am having a problem with searching of records in join table fields.I need all of the columns to be searched including join table column.</p>
  
  <p>Here is my controller function for All State with Country:</p>
  
  <pre><code>public function allStates()
  {
      $states = State::select(['id', 'country_id', 'state_type', 'state_code', 'state_name', 'status'])-&gt;orderBy('country_id','Asc');
      return Datatables::of($states)
          -&gt;addColumn('checkes', function ($states) {
  
              $data = $states;
              return view('partials.datatable.table_first_column_checkbox', compact('data'))-&gt;render();
          })
          -&gt;editColumn('country_id', function ($states) {
              return  $states-&gt;country ? $states-&gt;country-&gt;country_name : "N/A";
          })
          -&gt;editColumn('status', function ($states) {
  
              $data = $states;
              $statusChangeRoute = route('state.change.status');
              return view('partials.datatable.status-switch', compact('data','statusChangeRoute'))-&gt;render();
          })
          -&gt;addColumn('action', function ($states) {
  
              $editRoute = route('states.edit', $states-&gt;id);
              $viewRoute = route('states.show', $states-&gt;id);
              $controlKeyword = 'state';
              return view('partials.datatable.table_edit_delete_action', compact('editRoute','viewRoute','controlKeyword'))-&gt;render();
          })
          -&gt;addColumn('DT_RowId', function ($states) {
  
              return "tr_" . $states-&gt;id;
          })
          -&gt;rawColumns(['checkes', 'status', 'action'])
          -&gt;make(true);
  }
  </code></pre>
  
  <p>In this function I just edited <code>country_id</code> column and return <code>$states-&gt;country-&gt;country_name</code></p>
  
  <p>and here is my js function :</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      $(document).ready(function () {
          table = $('#tblState').DataTable({
              processing: true,
              serverSide: true,
              pageLength: 10,
              ajax: {
                  url: "{{ route('admin.states.list') }}",
                  type: "POST",
                  data: {_token: "{{csrf_token()}}"}
              },
              columns: [
                  {data: 'checkes',    name: 'checkes', orderable: false, searchable: false},
                  {data: 'country_id', name: 'country_id'},
                  {data: 'state_type', name: 'state_type'},
                  {data: 'state_code', name: 'state_code'},
                  {data: 'state_name', name: 'state_name'},
                  {data: 'status',     name: 'status'},
                  {data: 'action',     name: 'action', orderable: false, searchable: false}
              ],
              "bStateSave": true,
              initComplete: function (settings, json) {
                  // called on first time initialization
              },
              drawCallback: function (settings) {
                  // called on every server request
                  // below function is compulsory put here with table id param
                  initDTCheckBox('tblState');
              }
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>Here is my view screen</p>
  
  <p><a href="https://i.stack.imgur.com/xTnbi.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xTnbi.jpg" alt="enter image description here"></a></p>