laravel-datatables icon indicating copy to clipboard operation
laravel-datatables copied to clipboard

Default total records (length) to API

Open SergioFloresG opened this issue 7 years ago • 3 comments

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

SergioFloresG avatar Jan 30 '18 19:01 SergioFloresG

Good! I will create a branch for this feature. Or your created the branch?

SergioFloresG avatar Mar 06 '18 00:03 SergioFloresG

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".

THPAdmin avatar Nov 15 '23 20:11 THPAdmin

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.

yajra avatar Nov 16 '23 01:11 yajra