Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method to check if current request is a POST request. #1517

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions laravel/documentation/requests.md
Expand Up @@ -62,6 +62,13 @@ Sometimes you may need to determine if the current URI is a given string, or beg
// This request is over HTTPS!
}

#### Determining if the current request is a POST request:

if (Request::is_post())
{
// This request is a POST request!
}

#### Determining if the current request is an AJAX request:

if (Request::ajax())
Expand Down
12 changes: 12 additions & 0 deletions laravel/request.php
Expand Up @@ -45,6 +45,18 @@ public static function method()
return ($method == 'HEAD') ? 'GET' : $method;
}

/**
* Determine if the current request is a POST request.
*
* @return string
*/
public static function is_post()
{
$method = static::foundation()->getMethod();

return ($method == 'POST') ? true : false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just return $method == 'POST'?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fast haha

}

/**
* Get a header from the request.
*
Expand Down