Php Laravel 5.1方法不允许在使用资源控制器的存储方法上出现HttpException
我试图使用资源控制器向数据库添加一条记录,但是,我收到MethodNotAllowedHttpException错误。我曾经遇到过几个类似的问题,比如,或者,但是,似乎没有一个能回答我。这是我的代码: Routes.phpPhp Laravel 5.1方法不允许在使用资源控制器的存储方法上出现HttpException,php,rest,laravel,laravel-5.1,Php,Rest,Laravel,Laravel 5.1,我试图使用资源控制器向数据库添加一条记录,但是,我收到MethodNotAllowedHttpException错误。我曾经遇到过几个类似的问题,比如,或者,但是,似乎没有一个能回答我。这是我的代码: Routes.php Route::resource('animals', 'AnimalsCtrl'); 我模型的一部分 protected $table='animals'; protected $primaryKey='name'; protected $fillable = [
Route::resource('animals', 'AnimalsCtrl');
我模型的一部分
protected $table='animals';
protected $primaryKey='name';
protected $fillable = [
'name', 'type'
];
控制器中的存储方法
public function store(Request $request)
{
$creature = $request->all();
Animal::create($creature);
}
这是表格
<form method="post">
<div class="small-6 small-centered large-4 large-centered columns">
{!! csrf_field() !!}
<table>
<tr>
<th scope="row">Name</th>
<td>
<input type="text" name="name" maxlength="50" required>
</td>
</tr>
<tr>
<th scope="row">Type</th>
<td>
<input type="text" name="type" maxlength="20" required>
</td>
</tr>
<tr>
<th>
<button type="submit" class="button success">
<i class="fi-plus"></i>
Add Animal
</button>
</th>
<td>
<a href="{{url('/animals')}}" class="button alert">
<i class="fi-x-circle"></i>
Cancel
</a>
</td>
</tr>
</table>
</div>
</form>
{!!csrf_field()!!}
名称
类型
加动物
有人对我如何解决这个问题有什么建议吗?当您发布表单时,您将表单发布到的URL是什么?url应该在操作中。例如:
<form action="/animals" method="post">
</form>
我可能错了,但我认为您缺少表单中的操作参数 试试这个:
<form action="/animals" method="post">
而不是这个
<form method="post">
作为提示,我建议您使用HTML表单外观。看看这个:
这是Laravel 5.1的文档如果您认为此答案解决了您的问题,请将此标记为下一位与会者的答案。-谢谢