Donations Appreciated

There is no exercise better for the heart than reaching down and lifting people up. - John Holmes

Click here to lend your support to: Laravel Datatables and make a donation at !

RelationController.php - Belongs To Many Demo

Id Name Email Post


    public function getBelongsToMany(Request $request)
        if ($request->ajax()) {
            $query = User::with('blogs')->selectRaw('distinct users.*');

            return $this->dataTable
                ->addColumn('title', function (User $user) {
                    return $user->blogs->map(function($blog) {
                        return str_limit($blog->title, 30, '...');

        return view('datatables.relation.belongs-to-many', [
            'title' => 'Belongs To Many Demo',
            'controller' => 'Relation Controller',


        processing: true,
        serverSide: true,
        ajax: '',
        columns: [
            {data: 'id', name: ''},
            {data: 'name', name: ''},
            {data: 'email', name: ''},
            {data: 'title', name: 'blogs.title'},