No one has ever become poor by giving. - Anne Frank, diary of Anne Frank
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('https://api.github.com/search/repositories', [
'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) .'">
</div>';
})
->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
->make(true);
}
$('#datatable').dataTable({
processing: true,
serverSide: true,
ajax: 'https://datatables.yajrabox.com/collection/github-data',
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
}).fnFilterOnReturn();