Skip to content

Instantly share code, notes, and snippets.

@bishoyAtif
Last active May 25, 2018 09:24
Show Gist options
  • Save bishoyAtif/8719c8cd5674ce9eae4b5c762b7b01ff to your computer and use it in GitHub Desktop.
Save bishoyAtif/8719c8cd5674ce9eae4b5c762b7b01ff to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Controllers\Ajax;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use DataTables;
use App\Post;
class PostController extends Controller
{
public function index()
{
return Datatables::of(Post::query()->with('comments', 'user'))
->addColumn('user_name', function($row){
return $row->user->name;
})
->addColumn('comments_num', function($row){
return $row->comments->count();
})
->make(true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment