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 >PHP Framework >Laravel >How to verify request method in laravel
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')".
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']);
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!