Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default total records (length) to API #1597

Open
SergioFloresG opened this issue Jan 30, 2018 · 3 comments
Open

Default total records (length) to API #1597

SergioFloresG opened this issue Jan 30, 2018 · 3 comments

Comments

@SergioFloresG
Copy link

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
Copy link
Author

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

@THPAdmin
Copy link

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

@yajra
Copy link
Owner

yajra commented Nov 16, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants