Donations Appreciated

You have not lived today until you have done something for someone who can never repay you. - John Bunyan

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

CollectionController.php - Collection Demo using Github API as data source

Stars Repo Owner Description Private


    public function getGithub()
        return view('datatables.collection.github');

    public function getGithubData()
        $search = $request->get('search');
        $keyword = $search['value']?: 'laravel';
        $repositories = Cache::get($keyword, function() use($keyword) {
            $client = new \GuzzleHttp\Client();
            $response = $client->get('', [
                    'query' => ['q' => $keyword]
            $repositories = $response->json();
            Cache::put($keyword, $repositories, 10);

            return $repositories;

        $data = new Collection($repositories['items']);

        return Datatables::of($data)
            ->editColumn('stargazers_count', function($row) {
                return '<div class="input-group input-group-sm">
                            <span class="input-group-addon"><i class="glyphicon glyphicon-star"></i></span>
                            <input type="text" class="form-control" style="width:64px" readonly
                                value="'. number_format($row['stargazers_count'] , 0) .'">
            ->editColumn('full_name', function($row) {
                return HTML::link($row['html_url'], $row['full_name']);
            ->editColumn('private', function($row) {
                return $row['private'] ? 'Y' : 'N';
            ->filter(function(){}) // disable built-in search function


        processing: true,
        serverSide: true,
        ajax: '',
        columns: [
            {data: 'stargazers_count', name: 'stargazers_count'},
            {data: 'full_name', name: 'full_name'},
            {data: 'owner.login', name: 'owner.login', orderable: false, searchable: false},
            {data: 'description', name: 'description'},
            {data: 'private', name: 'private'}
        order: [[0, 'desc']],
        displayLength: -1