You have not lived today until you have done something for someone who can never repay you. - John Bunyan
Id | Title | Tag |
---|
public function getMorphToMany(Request $request)
{
if ($request->ajax()) {
$query = Post::with('tags')->select('posts.*');
return $this->dataTable->eloquent($query)
->addColumn('tags', function (Post $post) {
return $post->tags->pluck('name')->implode('<br>');
})
->make(true);
}
return view('datatables.relation.morph-to-many', [
'title' => 'Morph To Many Demo',
'controller' => 'Relation Controller',
]);
}
$('#users-table').DataTable({
processing: true,
serverSide: true,
ajax: '',
columns: [
{data: 'id', name: 'posts.id'},
{data: 'title', name: 'posts.title'},
{data: 'tags', name: 'tags.name'},
]
});