我有一个路由资源Route :: resource(‘projects’,’ProjectsController’);当我运行route:list时,我可以看到POST可用.
+--------+----------+--------------------------+------------------+--------------------------------------------------------------+-----------------+ | Domain | Method | URI | Name | Action | Middleware | +--------+----------+--------------------------+------------------+--------------------------------------------------------------+-----------------+ | | GET|HEAD | projects | projects.index | App\Http\Controllers\ProjectsController@index | auth | | | POST | projects | projects.store | App\Http\Controllers\ProjectsController@store | auth | | | GET|HEAD | projects/create | projects.create | App\Http\Controllers\ProjectsController@create | auth | | | GET|HEAD | projects/{projects} | projects.show | App\Http\Controllers\ProjectsController@show | auth | | | PUT | projects/{projects} | projects.update | App\Http\Controllers\ProjectsController@update | auth | | | PATCH | projects/{projects} | | App\Http\Controllers\ProjectsController@update | auth | | | DELETE | projects/{projects} | projects.destroy | App\Http\Controllers\ProjectsController@destroy | auth | | | GET|HEAD | projects/{projects}/edit | projects.edit | App\Http\Controllers\ProjectsController@edit | auth | +--------+----------+--------------------------+------------------+--------------------------------------------------------------+-----------------+
当我在/ projects / create(显示我的表单)并点击我的提交按钮时,我收到一条错误消息:
MethodNotAllowedHttpException in RouteCollection.PHP line 201: at RouteCollection->methodNotAllowed(array('GET','HEAD','PUT','PATCH','DELETE')) in RouteCollection.PHP line 188
是我如何定义我的< form>标签?我没有使用正确的动作吗?
< form method =“post”action =“”>
我也试过< form method =“post”action =“{{url('projects / store')}}”>
对不起,我是拉夫拉的菜鸟!
您应该POST到资源URL,而不是资源/创建.
原文链接:https://www.f2er.com/laravel/130648.html换句话说,只需确保表单的操作是action =“/ projects”而不是action =“/ projects / create”
编辑:
我会把它留在这里,因为它有点相关,而且因为我最初发布它,但是预先警告它对于刚刚开始的人来说是过度杀伤和许多不相关的代码.
例如,这是我的一个站点的刀片片段:
@extends('layouts.master') @section('title','Create a Project') @section('content') <h3>Create a Project</h3> <hr/> {!! Form::open(['action'=>'ProjectController@store']) !!} @include('forms/partials/edit_form',['submit_button_label' => 'Add Project']) {!! Form::close() !!} @include('errors.list') @endsection