It's not how much we give but how much love we put into giving. - Mother Teresa
Id | Name | Post |
---|
public function getBelongsToMany(Request $request)
{
if ($request->ajax()) {
$query = User::with('blogs')->selectRaw('distinct users.*');
return $this->dataTable
->eloquent($query)
->addColumn('title', function (User $user) {
return $user->blogs->map(function($blog) {
return str_limit($blog->title, 30, '...');
})->implode('<br>');
})
->make(true);
}
return view('datatables.relation.belongs-to-many', [
'title' => 'Belongs To Many Demo',
'controller' => 'Relation Controller',
]);
}
$('#users-table').DataTable({
processing: true,
serverSide: true,
ajax: 'https://yajratables.tuecus.com/relation/belongs-to-many',
columns: [
{data: 'id', name: 'users.id'},
{data: 'name', name: 'users.name'},
{data: 'email', name: 'users.email'},
{data: 'title', name: 'blogs.title'},
]
});