[8.x] Add integer() method to InteractsWithInput trait#39714
[8.x] Add integer() method to InteractsWithInput trait#39714BrendanKoral wants to merge 2 commits intolaravel:8.xfrom BrendanKoral:feature/retrieve-request-input-as-integer
Conversation
|
The $query and $request properties of the $request object are instances of Symfony\Component\HttpFoundation\ParameterBag, so you can use the getInt method of it like this: Anyway, \Illuminate\Http\Request class already has a method called boolean. It depends, these proxy methods may be helpful or I can just cast values manually, it's fine. |
| * | ||
| * Returns an integer when value is a boolean or a number in string form i.e. "123". Otherwise, returns false. | ||
| * | ||
| * @param null $key |
| * Returns an integer when value is a boolean or a number in string form i.e. "123". Otherwise, returns false. | ||
| * | ||
| * @param null $key | ||
| * @param false $default |
|
|
Thanks for your pull request to Laravel! Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include. If possible, please consider releasing your code as a package so that the community can still take advantage of your contributions! If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response. |
This PR is inspired by the
boolean()method on theInteractsWithInputtrait. I often find that I have to write something like this when reading numbers out of a request:This PR eliminates the typecasting by adding an
integer()method similar to theboolean()method.If there's already an existing way to do something like this and I've overlooked it, please let me know. I didn't see anything like this in the documentation.