Die*_*ves 3 php rest http laravel
我知道这个问题可能已经提出,但我就是无法让它发挥作用。如果有人可以帮助我,我将非常感激。我安装了 colletive/form,但答案也可以是 html 表单标签。
现在列出我的表格、我的路线和我的例外情况。
{{ Form::model( array('route' => array('casas.update', 238), 'method' => 'PUT')) }}
<input type="hidden" name="_method" value="PUT">
Run Code Online (Sandbox Code Playgroud)
-
Route::resource('casas', 'CasasController');
Run Code Online (Sandbox Code Playgroud)
异常: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>
Run Code Online (Sandbox Code Playgroud)
Wirth Laravel Collective 它可能看起来像
{{ Form::model($casa, ['route' => ['casas.update', $casa->id], 'method' => 'put']) }}
{{-- Your form fields go here --}}
{{ Form::submit('Update') }}
{{ Form::close() }}
Run Code Online (Sandbox Code Playgroud)
在这两种情况下,都假设您将模型实例传递$casa
到刀片模板中
在你的控制器中
{{ Form::model($casa, ['route' => ['casas.update', $casa->id], 'method' => 'put']) }}
{{-- Your form fields go here --}}
{{ Form::submit('Update') }}
{{ Form::close() }}
Run Code Online (Sandbox Code Playgroud)