Using the Query Builder with a limit() value of zero causes Laravel to ignore the limit. This can cause some unexpected edge case issues for some code since devs assume that limit(0) would return no results. I believe this is the underlying cause of https://github.com/laravel/framework/issues/9960 as well.
Looking at the Laravel Query Builder code, it looks like if the $limit value is <= 0, that is assumed to indicate that no limit has been set. So a better design might be to use null to indicate the no limit has been set. I'm pretty sure a fix involves editing the database Grammars of the various database implementations. I'm not sure I'm feeling confident enough with my familiarity with Query Builder's internals to come up with a PR for this one, but I can give it a shot if this is something that should be fixed and no one else wants to do it.
Do you really need to execute query statements with LIMIT 0? That's terrifying.
Looks like an issue with your app rather than us. You should never be executing a select limit 0.
There is an expected behavior for LIMT 0 that should be handled properly by the framework since it is valid in SQL.
Yes, this edge case can be handled by the app, but it would be better if the framework handled this it better (and Laravel is usually all about taking as much of the burden off of the app developer as possible). If a developer doesn't know about this issue and assumes limit() can properly handle 0, they wouldn't know they they have to handle that case in their own app. Right now limit(0) returns _all_ results, which certainly isn't the expected behavior. Throwing an exception would be better than that.
Fixed in 5.1. Will be available in next tagged release.
Most helpful comment
There is an expected behavior for LIMT 0 that should be handled properly by the framework since it is valid in SQL.
Yes, this edge case can be handled by the app, but it would be better if the framework handled this it better (and Laravel is usually all about taking as much of the burden off of the app developer as possible). If a developer doesn't know about this issue and assumes limit() can properly handle 0, they wouldn't know they they have to handle that case in their own app. Right now limit(0) returns _all_ results, which certainly isn't the expected behavior. Throwing an exception would be better than that.