laravel-datatables
laravel-datatables copied to clipboard
Default total records (length) to API
Feature request
Hello, we are developing an api and we are certainly interested in using your component.
We have consulted the documentation but there is no element that allows us to define in the configuration the amount of elements to obtain by default.
The application is an API, it does not have direct interaction with a site or Javascript.
'search' => [
/*
* Sets the amount of item to obtain by default.
* It must be a positive integer.
*
* 0: without limit
*/
'length' => 20,
datatables()->eloquent( $query )
->setDefaultLength(30)
->make()
Regards
System details
- Amazon Linux AMI / Windows Server 2018
- PHP 7.0.21
- laravel/lumen-framework 5.5
- illuminate/database 5.5
Good! I will create a branch for this feature. Or your created the branch?
Did this ever get added? I was doing some debugging on a json endpoint, and it pulls 9,300 records and freezes my browser, lol. All an attacker would have to do is keep refreshing the endpoints on multiple computers and it would probably bring our servers to a crawl. Rather than a "default" length, I was more looking for a "maximum limit".
I think this was not implemented. Actually, they can just set the length
request to -1
to get all the records.
Given this, maybe you can create a middleware to set the maximum length overriding the request?
request()->merge(['length' => -1]); // Get all records
if (request('length') > 100) {
request()->merge(['length' => 100]);
}
Feel free to submit a PR, I also think this would be a great feature to implement.