Donations Appreciated

The simplest acts of kindness are by far more powerful then a thousand heads bowing in prayer. - Mahatma Gandhi

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'},