Eloquent DataTable with Has Many Through

Id Name Post

HTML

<table id="country-posts-table" class="table table-bordered">
    <thead>
    <tr>
        <th>Id</th>
        <th>Name</th>
        <th>Post</th>
    </tr>
    </thead>
</table>

Routes

<?php

Route::get('eloquent/has-many-through', 'Eloquent\HasManyThroughController@index');
Route::get('eloquent/has-many-through-data', 'Eloquent\HasManyThroughController@data');

Controller

<?php

namespace App\Http\Controllers\Eloquent;

use App\Country;
use App\Http\Controllers\Controller;
use Yajra\Datatables\Datatables;

class HasManyThroughController extends Controller
{
    /**
     * Display index page.
     *
     * @return \BladeView|bool|\Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index()
    {
        return view('eloquent.has-many-through');
    }

    /**
     * Process dataTable ajax response.
     *
     * @param \Yajra\Datatables\Datatables $datatables
     * @return \Illuminate\Http\JsonResponse
     */
    public function data(Datatables $datatables)
    {
        $query = Country::with('posts')->select('countries.*');

        return $datatables->eloquent($query)
                          ->addColumn('title', function (Country $country) {
                              return $country->posts->implode('title', '<br>');
                          })
                          ->rawColumns(['title'])
                          ->make(true);
    }
}

JS