[Proposal] Add isPost, isGet etc methods to Illuminate\Http\Request
I found myself using the following code a few times in an application when I wanted to use the same controller method for both get and post requests:
if( Request::getMethod() == 'POST')
I thought it might be more elegant to be able to write:
if( Request::isPost())
Could also then add isGet, isPut etc..
Maybe a Request::is('GET') ?
Request::is('admin/*') is already there.
Sorry about my suggestion based on lack of my knowledge then. Request::isPost() or Request::isGet are better solutions, and even though it can be achieved by the getMethod, i believe those would be more elegant solutions.
The is method already exists for checking the requested uri against a pattern.
Symfony Request is already have a method named isMethod. You can see it here:
https://github.com/symfony/HttpFoundation/blob/master/Request.php#L1404
I made a test in Laravel if it is working already and it does.
So you can make:
if( Request::isMethod('POST') ) instead of if( Request::getMethod() == 'POST')
So there is no need for this proposal, perhaps consider making a pull request to docs if you want to add it.
Yes, you are right there is no need for this proposal if the underlying Symfony class has a suitable method. I will take a look at the docs and see if I can see a natural place for this detail to potentially be added.
Maybe there is a wider question about whether the Laravel docs could do more to point people to additional methods which are available from the Symfony classes.