isMethod('post') ){code to be executed}"."/> isMethod('post') ){code to be executed}".">

Home  >  Article  >  PHP Framework  >  How does laravel determine whether it is post transmission?

How does laravel determine whether it is post transmission?

WBOY
WBOYOriginal
2022-06-02 17:22:542605browse

In laravel, you can use the isMethod method of the Request object with the if statement to determine whether it is a post transmission request. Just set the parameter to "post", and the syntax is "if($request-> ;isMethod('post')){code to be executed}".

How does laravel determine whether it is post transmission?

The operating environment of this article: Windows 10 system, Laravel version 5.4, Dell G3 computer.

How does laravel determine whether it is post transmission?

You can use post transmission to determine whether the form form has a value. Post it:

if($request->isMethod('post')){
    // 要执行的代码
}

It is done through the isMethod method of the Request object. judge!

Examples are as follows:

Judge whether it is a get or post request

public function interview_add(Request $request,int $id){
    if($request->isMethod('get')){
        //get执行的代码
    }elseif ($request->isMethod('post')){
        //post执行的代码
    }
}

Extended knowledge:

PHP, laravel acquisition Post requested params, xml, json

Get all params

//php原生写法
$content = $_POST;
//或者
$content = file_get_contents(“php://input”);
//laravel写法
$content = $request->all();

Get xml, json

// 原生php写法
$content = file_get_contents("php://input");
// laravel框架写法
$content = $request->getcontent();

[Related recommendations: laravel video tutorial]

The above is the detailed content of How does laravel determine whether it is post transmission?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn