php - RESTful Laravel controller not picking up Destroy() method -
structure: views/agents/alert/index.blade.php form delete 'notification':
{{ form::open( array('url'=>'agents/alert/delete/'. $alerts->id, 'role'=>'form')) }} {{ form::hidden('_method', 'delete') }} <button type="submit" class="btn btn-warning" id="archive">archive</button> {{ form::close() }} agentscontroller:
public function destroy($id) { $alert = alert::find($id); $alert->delete(); return redirect::to('/agents/') ->with('message-success', 'your alert archived.'); } routes.php: /* agent's route */
route::get('agents/alert/{id}', 'agentscontroller@show'); route::get('agents/alert/delete/{id}', 'agentscontroller@destroy'); route::controller('agents', 'agentscontroller'); i correctly referencing url called when user presses delete, however, error presented 'controller method not found'.
any i'd thankful of.
you should perform delete on resource.
if have alert unique url agents/alert/{id} should delete method on same url.
route::delete('agents/alert/{id}', 'agentscontroller@destroy'); create form can submitted delete resource:
{{ form::open(array('method' => 'delete', 'action' => array('agentscontroller@destroy', $alert->id))) }} more information on restful controllers here.
also try use named routes instead of action.
Comments
Post a Comment