MethodNotAllowedHttpException Laravel 5.3

时间:2016-11-01 14:47:44

标签: laravel-5 httpexception

我无法更新或删除,尤其是当我在路径文件

中添加Route :: resource(....)时
  

web.php(路线文件)

Route::resource('home/activity','ActivityController');

  

edit.blade.php

{!!Form::model($activity,['action' => ['ActivityController@update',$activity->id]])!!}

<div class="form-group">
  {!! Form::label('Type :') !!} {!! Form::text('type',null,['class'=>'form-control']) !!}
</div>

<button class="btn btn-primary">Editer</button>

{!!Form::close()!!}

<br>
{!!Form::open(['Methode'=>'Delete','action' => ['ActivityController@destroy',$activity->id]])!!}

  {!! Form::submit('Delete',['class'=> 'btn btn-danger']) !!} 

{!! Form::close() !!}

  

模型

  protected $table ='activities';
 protected $fillable =['type']

  

ActivityController

    public function update($id,Request $request){
        $activity = activity::findOrFail($id);
        $activity->update($request->all());
        return redirect('/home/activity');
    }

    public function destroy($id){
       Activity::destroy($id);
       return redirect('/home/activity');
    }

**谢谢

1 个答案:

答案 0 :(得分:1)

默认情况下Form::open()使用post方法请求。但是当您创建Route :: resource()时,update方法会接受put或patch请求。

因此,对于putpatch请求,您需要将其他参数传递为:

{{ Form::open(array('route' => array('activity.edit',$activity->id), 'method' => 'put')) }}

删除表格同样如下:

{{ Form::open(array('route' => array('activity.delete',$activity->id), 'method' => 'delete')) }}