In my controller/action:
if(!empty($_POST))
{
if(Auth::attempt(Input::get('data')))
{
return Redirect::intended();
}
else
{
Session::flash('error_message','');
}
}
Is there a method in Laravel
to check if the request is POST
or GET
?
The solutions above are outdated.
As per Laravel documentation:
According to Laravels docs, there's a Request method to check it, so you could just do:
or
$_SERVER['REQUEST_METHOD']
is used for that.It returns one of the following:
Use
Request::getMethod()
to get method used for current request, but this should be rarely be needed as Laravel would call right method of your controller, depending on request type (i.e.getFoo()
for GET andpostFoo()
for POST).Of course there is a method to find out the type of the request, But instead you should define a route that handles
POST
requests, thus you don't need a conditional statement.routes.php
inside you controller/action
The same goes for
GET
request.