I couldn't update or delete, especially when i add Route::resource(....) in route file
web.php (route file)
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() !!}
model
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');
}
**Thanks
By default Form::open()
uses post
method request. But when you create a Route::resource(), the update method takes a put or patch request.
So for a put
or patch
request you need to pass additional parameter as:
{{ Form::open(array('route' => array('activity.edit',$activity->id), 'method' => 'put')) }}
Same goes for delete form as:
{{ Form::open(array('route' => array('activity.delete',$activity->id), 'method' => 'delete')) }}