duandai0373 2015-12-03 07:15
浏览 48
已采纳

无法更新laravel 5.1中的数据

I am trying to edit and update data in laravel but it's throwing an exception MethodNotAllowedHttpException in RouteCollection.php line 219: I have seen other people asking for same issue, but I am not able to understand from their perspective, I am watching tutorials and doing step by step, I have done some research on my own but I am very new to php and framework world so stuck now, here is route code:

Route::get('aboutus', ['as' => 'about', 'uses' => 'PagesController@about']);
Route::get('authors', array('as' => 'authors', 'uses' => 'authors_controller@get_index'));
Route::get('authors/new', array('as' => 'new_author', 'uses' => 'authors_controller@get_new'));
Route::get('authors/{id}', array('as' => 'authorRoute', 'uses' => 'authors_controller@get_view'));
Route::post('authors/authorsWithData', array('as' => 'authorsWithData', 'uses' => 'authors_controller@store'));
Route::get('authors/{id}/edit', array('uses' => 'authors_controller@edit'));
Route::post('authors/{id}/update', array('uses' => 'authors_controller@update'));

controller code:

public function update($id, CreateAuthorRequest $request){
    $author = author::find($id);
    $author->update($request->all());
    return view('authors.view');
}

edit.blade.php code:

        {!! Form::model($author, ['method'=> 'PATCH', 'url' => ['authors/' . 
        $author->id . '/update']]) !!}

    {!! Form::label('name', 'Name:', ['id' => 'labelId']) !!}
    {!! Form::text('name', Input::old('name'), '' 
    , ['id' => 'nameId', 'placeholder' => 'name goes here']) !!}

    <p>
        {!! Form::label('bio', 'Biography:') !!}<br />
        {!! Form::textarea('bio', Input::old('name')) !!}
    </p>    

    <p> {!! Form::submit('Add Author') !!}</p> 

    {!! Form::close() !!}        
  • 写回答

2条回答 默认 最新

  • dongxian8048 2015-12-03 07:25
    关注

    Your route should be accepting a PATCH request, not a POST request.

    This is your form:

    {!! Form::model($author, ['method'=> 'PATCH', 'url' => ['authors/' . 
        $author->id . '/update']]) !!}
    

    You specified that method is equal to PATCH. So, in your corresponding route, you need to match that:

    Old route:

    Route::post('authors/{id}/update', array('uses' => 'authors_controller@update'));
    

    New route:

    Route::patch('authors/{id}/update', array('uses' => 'authors_controller@update'));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 MATLAB怎么通过柱坐标变换画开口是圆形的旋转抛物面?
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿