该路由不支持POST方法。支持的方法:GET,HEAD

时间:2019-04-10 04:58:44

标签: laravel

我尝试使用post方法更新特定数据。提交表单后,它显示错误:此路由不支持POST方法。支持的方法:GET,HEAD。

editpage.blade.php

@extends('layouts.app')

@section('content')
<div class="container">
    <h3>Update Book</h3>
    <br>
    <form action="update" method="post"  >

        {{csrf_field()}}

        @foreach($array as $fetch)

        <div><input type="hidden" name="id" value="{{$fetch->id}}"></div>
        <div><input type="text" name="name" class="form-control " placeholder="Bookname" value="{{$fetch->name}}" ></div><br>


        <div><textarea name="content" class="form-control" rows="5" placeholder="Description" >{{$fetch->content}}</textarea></div><br>

        <div><input type="text" name="author" class="form-control" placeholder="Author" value="{{$fetch->author}}"></div> <br>

        <div><input type="submit" name="submit" value="Update Book" class="btn btn-success" ></div>
        @endforeach
    </form>
</div>

@endsection

网络路线

Route::get('/', function () {
    return view('welcome');
});

Route::get('/addbook',function () {
    return view('AddBook');
});

Route::post('/insert',['uses'=>'BookController@insert']);
Route::get('/delete/{id}',['uses'=>'BookController@delete']);
Route::get('/edit/{id}',['uses'=>'BookController@edit']);

``````
Route::post('/update',['uses'=>'BookController@update']);

```````

Route::get('/home',['uses'=>'BookController@index']);

Auth::routes();

1 个答案:

答案 0 :(得分:1)

有些操作(例如更新)要求提交到服务器url的方法为PUT / PATCH(以修改资源)

尝试一下,

<form action="{{ route('book.update') }}" method="post"  >
    {{csrf_field()}}
    {{ method_field('PUT') }}

    @foreach($array as $fetch)
       // ...
    @endforeach
</form>

您的路线,

Route::put('update',['uses'=>'BookController@update', 'as' => 'book.update']);

您的控制器

public function update(Request $request)
{
    // ...
}

希望这会有所帮助:)