Check if request is GET or POST

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?


Solution 1:

According to Laravels docs, there's a Request method to check it, so you could just do:

$method = Request::method();

or

if (Request::isMethod('post'))
{
// 
}

Solution 2:

The solutions above are outdated.

As per Laravel documentation:

$method = $request->method();

if ($request->isMethod('post')) {
    //
}