1. Go to this page and download the library: Download teamq/laravel-datatables library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
teamq / laravel-datatables example snippets
return [
'parameters' => [
'per_page' => 'per_page',
],
'per_page' => [
// Represents the value to be sent by the user, to obtain all records, if using the result method.
'all' => 'all',
],
];
GET /books?per_page=30
use Spatie\QueryBuilder\AllowedFilter;
use TeamQ\Datatables\QueryBuilder;
use TeamQ\Datatables\Filters\TextFilter;
$query = QueryBuilder::for(Book::class);
$query->result();
GET /books?filter[isbn][value]=54213&filter[isbn][operator]=$lt
use Spatie\QueryBuilder\AllowedFilter;
use TeamQ\Datatables\QueryBuilder;
use TeamQ\Datatables\Filters\TextFilter;
QueryBuilder::for(Book::class)
->allowedFilters([
AllowedFilter::custom('isbn', new TextFilter()),
]);
use Spatie\QueryBuilder\AllowedFilter;
use TeamQ\Datatables\QueryBuilder;
use TeamQ\Datatables\Filters\TextFilter;
use TeamQ\Datatables\Enums\JoinType;
QueryBuilder::for(Book::class)
->allowedFilters([
AllowedFilter::custom('isbn', new TextFilter(false, JoinType::Inner)),
]);
GET /books?filter[isbn][value]=54213&filter[isbn][operator]=$endWith
use Spatie\QueryBuilder\AllowedFilter;
use TeamQ\Datatables\QueryBuilder;
use TeamQ\Datatables\Filters\TextFilter;
QueryBuilder::for(Book::class)
->allowedFilters([
AllowedFilter::custom('isbn', new TextFilter()),
]);
GET /books?filter[id][value][0]=1&filter[id][value][1]=5&filter[id][value][2]=9&filter[id][operator]=$in
use Spatie\QueryBuilder\AllowedFilter;
use TeamQ\Datatables\QueryBuilder;
use TeamQ\Datatables\Filters\NumberFilter;
QueryBuilder::for(Book::class)
->allowedFilters([
AllowedFilter::custom('id', new NumberFilter()),
]);
GET /books?filter[created_at][value][0]=2019-08-01&filter[created_at][value][1]=2019-08-10&filter[created_at][operator]=$notBetween
use Spatie\QueryBuilder\AllowedFilter;
use TeamQ\Datatables\QueryBuilder;
use TeamQ\Datatables\Filters\DateFilter;
QueryBuilder::for(Book::class)
->allowedFilters([
AllowedFilter::custom('created_at', new DateFilter()),
]);
GET /books?filter[search]='Luis'
use Spatie\QueryBuilder\AllowedFilter;
use TeamQ\Datatables\QueryBuilder;
use TeamQ\Datatables\Filters\GlobalFilter;
QueryBuilder::for(Book::class)
->allowedFilters([
AllowedFilter::custom('search', new GlobalFilter([
'author.name',
'title',
])),
]);
GET /books?filter[has_books]=1
use Spatie\QueryBuilder\AllowedFilter;
use TeamQ\Datatables\QueryBuilder;
use TeamQ\Datatables\Filters\HasRelationshipFilter;
QueryBuilder::for(Author::class)
->allowedFilters([
AllowedFilter::custom('has_books', new HasRelationshipFilter(), 'books'),
]);
use Spatie\QueryBuilder\AllowedFilter;
use TeamQ\Datatables\QueryBuilder;
use TeamQ\Datatables\Sorts\RelationSort;
QueryBuilder::for(Book::class)
->allowedSorts([
AllowedSort::custom('author.name', new RelationSort(JoinType::Inner)),
])
use Spatie\QueryBuilder\AllowedFilter;
use TeamQ\Datatables\QueryBuilder;
use TeamQ\Datatables\Sorts\CaseSort;
QueryBuilder::for(Book::class)
->allowedSorts([
AllowedSort::custom('state', new CaseSort([
1 => 'Active',
2 => 'Rejected',
3 => 'Deleted',
4 => 'Completed',
])),
]);