该路由不支持POST方法。支持的方法:PUT,PATCH,DELETE

时间:2019-04-12 11:17:13

标签: php web laravel-5 eloquent

不起作用 显示此

  

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException此路由不支持POST方法。支持的方法:PUT,PATCH,DELETE。

{
  "name": "hd",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "generate-api-client": "call ../../Build/GenerateApiClient.bat",
    "predevbuild": "cpx ./src/styles/theme.config ./node_modules/semantic-ui-less/",
    "devbuild": "ng build --output-hashing none",
    "prebuild": "cpx ./src/styles/theme.config ./node_modules/semantic-ui-less/",
    "build": "ng build --prod --output-hashing none",
    "watch": "ng build --output-hashing none --watch",
    "test": "ng test --sourceMap=false --watch false",
    "test-watch": "ng test --sourceMap=false",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "6.0.7",
    "@angular/common": "6.0.7",
    "@angular/compiler": "6.0.7",
    "@angular/core": "6.0.7",
    "@angular/forms": "6.0.7",
    "@angular/http": "6.0.7",
    "@angular/platform-browser": "6.0.7",
    "@angular/platform-browser-dynamic": "6.0.7",
    "@angular/router": "6.0.7",
    "core-js": "2.5.7",
    "date-fns": "1.29.0",
    "element-resize-detector": "1.1.14",
    "lodash-es": "4.17.10",
    "ng2-semantic-ui": "0.9.7",
    "rxjs": "6.2.1",
    "semantic-ui-calendar": "0.0.8",
    "semantic-ui-less": "2.3.3",
    "zone.js": "0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "0.6.8",
    "@angular/cli": "6.0.8",
    "@angular/compiler-cli": "6.0.7",
    "@angular/language-service": "6.0.7",
    "@types/element-resize-detector": "1.1.0",
    "@types/jasmine": "2.8.8",
    "@types/jasminewd2": "2.0.3",
    "@types/lodash-es": "4.17.0",
    "@types/node": "10.5.3",
    "codelyzer": "4.4.2",
    "cpx": "1.5.0",
    "jasmine": "3.1.0",
    "jasmine-core": "3.1.0",
    "jasmine-spec-reporter": "4.2.1",
    "karma": "2.0.4",
    "karma-chrome-launcher": "2.2.0",
    "karma-cli": "1.0.1",
    "karma-coverage-istanbul-reporter": "2.0.1",
    "karma-jasmine": "1.1.2",
    "karma-jasmine-html-reporter": "1.2.0",
    "less": "2.7.3",
    "protractor": "5.3.2",
    "ts-node": "7.0.0",
    "tslint": "5.10.0",
    "typescript": "2.7.2"
  }
}

3 个答案:

答案 0 :(得分:1)

可用的路由器方法 路由器允许您注册响应任何HTTP动词的路由:

Route::get($uri, $callback);
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::patch($uri, $callback);
Route::delete($uri, $callback);
Route::options($uri, $callback);

https://laravel.com/docs/5.8/routing

答案 1 :(得分:0)

在表单标签中像这样伪造您的补丁请求

<form class="form-ad" action="{{ route('jobs.store') }}" method="post" >
{{ method_field('POST') }} /*here i used post and solved the error*/ /*if you are using form method POST then what is the use of using {{method_field('POST')}} form "store" action? {{method_field('POST')}} is mainly used if you have a PATCH request for update action. Store action is already on POST request in your Routes.*/
<!-- rest of the form -->
</form>

此外,只是一个建议,您可以简单地使资源充满路径。

首先通过artisan命令使控制器足智多谋,这将创建每种方法所需的所有方法(获取,发布,修补等)

php artisan make:controller Jobs -r

然后在您的route / web.php中使用

Routes::resource('jobs');

您还可以使用php artisan命令查看您的路线

php artisan route:list

答案 2 :(得分:0)

在html视图中添加@csrf行 然后它工作post方法

add @csrf line in the html view 
then it work post method
-------------------------------------------------------------------

<form  method="post" action="users" class="UserController">
    {{method_field('post')}}
    @csrf
    <input type="text" name="user" placeholder="enter name"><br/><br/>
    <input type="password" name="password" placeholder="enter password"><br/><br/>
    <button type="submit" value="submit">Submit</button>
</form>