2016-11-01 144 views
1

我不能更新或刪除,尤其是當我在路由文件添加路由::資源(....)MethodNotAllowedHttpException Laravel 5.3

web.php(路由文件)

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

edit.blade.php

{!!Form::model($activity,['action' => ['[email protected]',$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' => ['[email protected]',$activity->id]])!!} 
 

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

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

模型

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

ActivityControlle ř

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

默認Form::open()使用post方法請求。但是,當您創建Route :: resource()時,更新方法會接受放置或修補程序請求。

所以你需要傳遞額外的參數作爲putpatch要求:

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

也是一樣的刪除形式:

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

**感謝**的男人:) – meduprise

相關問題