method(), $_SERVER['REQUEST_METHOD'])" statement; 2. Use the isMethod method of the Request object, with the syntax "$request->isMethod('request type' )"."/> method(), $_SERVER['REQUEST_METHOD'])" statement; 2. Use the isMethod method of the Request object, with the syntax "$request->isMethod('request type' )".">

Home  >  Article  >  PHP Framework  >  How to verify request method in laravel

How to verify request method in laravel

青灯夜游
青灯夜游Original
2021-09-29 15:39:222097browse

Verification method: 1. Use the "dd(request()->method(), $_SERVER['REQUEST_METHOD'])" statement; 2. Use the isMethod method of the Request object, the syntax "$request- >isMethod('Request Type')".

How to verify request method in laravel

The operating environment of this tutorial: Windows 7 system, Laravel 6 version, Dell G3 computer.

In Laravel, sometimes we need to distinguish request types to return different results, so how to verify the request method? Two methods are introduced below.

Method 1:

dd(request()->method(), $_SERVER['REQUEST_METHOD']);

How to verify request method in laravel

Method 2: Judge through the isMethod method of the Request object

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

Related recommendations: The latest five Laravel video tutorials

The above is the detailed content of How to verify request method in laravel. 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