我知道这个问题可能已经提出,但我就是无法让它发挥作用。如果有人可以帮助我,我将不胜感激。我安装了集体/表单,但答案也可以是 html 表单标签。
现在列出我的表格、我的路线和我的异常。
{{ Form::model( array('route' => array('casas.update', 238), 'method' => 'PUT')) }}
<input type="hidden" name="_method" value="PUT">
-
Route::resource('casas', 'CasasController');
异常: RouteCollection.php 第 218 行中的 MethodNotAllowedHttpException:
最佳答案
使用纯 html/blade
<form action="{{ route('casas.update', $casa->id) }}" method="post">
{{ csrf_field() }}
{{ method_field('put') }}
{{-- Your form fields go here --}}
<input type="submit" value="Update">
</form>
Wirth Laravel Collective 它可能看起来像
{{ Form::model($casa, ['route' => ['casas.update', $casa->id], 'method' => 'put']) }}
{{-- Your form fields go here --}}
{{ Form::submit('Update') }}
{{ Form::close() }}
在这两种情况下,都假设您将模型实例 $casa
传递到您的 blade 模板中
在你的 Controller 中
class CasasController extends Controller
{
public function edit(Casa $casa) // type hint your Model
{
return view('casas.edit')
->with('casa', $casa);
}
public function update(Request $request, Casa $casa) // type hint your Model
{
dd($casa, $request->all());
}
}
关于php - 如何在 Laravel 中使用 PUT http 动词提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44864942/